Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- model Movement
- def to_param
- name.gsub(/ /, '-')
- end
- def self.find_by_param input
- find_by_name input.gsub(/-/, ' ')
- end
- end
- model Event
- def to_param
- name.gsub(/ /, '-')
- end
- def self.find_by_param input
- find_by_name input.gsub(/-/, ' ')
- end
- end
- # It can be solved by using module and submodule
- module ParamToName
- module ClassMethods
- def self.find_by_param input
- find_by_name input.gsub(/-/, ' ')
- end
- end
- def to_param
- name.gsub(/ /, '-')
- end
- def self.included(klass)
- klass.extend ClassMethods
- end
- end
- model Event
- include ParamToName
- end
- model Movement
- include ParamToName
- end
- Event.new.to_param
- Event.find_by_param input
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement