rails has_many association pass params to new form for create
I have a has_many association I would like to pass to the the list_advice_id to the New form for AdvisorConnection. My models are below:
class ListAdvice < ActiveRecord::Base
has_many :advisor_connections, :dependent => :destroy
end
class AdvisorConnection < ActiveRecord::Base
belongs_to :list_advice
belongs_to :users
end
On the list_advice show form, I have a li开发者_Python百科nk_to as shown below:
<td><%= link_to 'Book Advisor', new_advisor_connection_path %></td>
On the advisor_connections controller new action, I have:
@advisor_connection = AdvisorConnection.new
@advisor_connection = @list_advice.advisor_connection.find(params[:list_advice])
After looking at many examples, I don't know how to pull the list_advice_id into the advisor_connection new form so it will use the has_many association to show on New and then save on Create. Please help.
I'm pretty new to rails, too, so this might not be the correct answer. But it looks like you are trying to use multiple models on the same form. This railscast was very helpful to me
http://railscasts.com/episodes/196-nested-model-form-part-1
精彩评论