Created
December 26, 2008 00:49
-
-
Save nesquena/39984 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /app/views/families/show.html.haml | |
= link_to 'Send Message', new_family_message_path(:family_id => @family.id, :category => 'Family') | |
# /app/controllers/messages_controller.rb | |
def new | |
@category = params[:category] | |
render :action => "messages/#{@category}_form", :layout => true | |
end | |
# /app/views/messages/_family_form.html.haml | |
- form_for :message,:url => new_family_messages_path(:family_id => X) do |f| | |
= f.text_field :subject | |
= f.text_field :body | |
= f.submit | |
= hidden_field_tag :category, @category | |
# /app/controllers/messages_controller.rb | |
# params => { :xxxxx_id => x, :category => 'xxxx', :message => { ... } } | |
def create | |
@category = params[:category] # => 'Family' | |
@parent_id = params["#{@category.downcase}_id"] # => params[:family_id] | |
@[email protected](@parent_id) # => Family.find(...) | |
@messageable.messages.build(params[:message]) | |
#.... save and shit | |
end | |
# Resources | |
# * http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment