开发者

Passing a variable to the new.html.rb page

I have two MVCs Meeting and Agenda. A meeting can have many agenda items.

I am trying to set these two pages up so that I can click a 'Create New Agenda Item' on the show.html.rb meeting page. The idea being that this would redirect the user to the new.html.rb agenda page passing the meeting id, and pre-populating the new.html.rb agenda form with the meeting ID.

Currently I have the following which passes the meeting ID in the URL but I have no idea how to pass it to the form.

Meeting: show.html.rb:

<%= link_to "Add Agenda Item", :action => 'new_agenda', :id => @meeting.id %>

Go gentle, I'm very new开发者_JAVA技巧. But many thanks in advance.

Christian Macedo.


The new action within your Agenda controller should have access to the meeting ID query parameter. Something like:

def new
  @agenda = Agenda.new
  @agenda.meetings.build(Meeting.find(params[:id]))
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜