TAGS :Viewed: 5 - Published at: a few seconds ago
[ Nested resource form paths ]
this is my form
<%= form_for([@game,@message_template]) do |f| %>
and in my controller I do this:
def edit
@message_template = MessageTemplate.find(params[:id])
@game = Game.where(:slug => params[:game_id])
end
My route is like this /games/:game_id/message_templates/:id
But I am getting this
undefined method `model_name' for #
Answer 1
Try setting that arel search to return the first object (for @game).
def edit
@message_template = MessageTemplate.find(params[:id])
@game = Game.where(:slug => params[:game_id]).first
end
routes.rb:
#based on your comment, this will give you all (and likely more) of the paths you will need.
resources :games do
resources :message_templates
end