I currently have three models and I want to bring in a model from one of the models (webpage.id) Trying (microprost) - Here's the situation:
Class members & lt; ActiveRecord :: Base is_my: micropost and class webpage & lt; ActiveRecord :: Base_Mena: Microprost, Dependent = & gt; : And Class Microprost and Lt; ActiveRecord :: Base is_to: Member is_to: Webpage and What I'm trying to do is create a microprost with the webpage 'show' method.
Microprost Controller:
Class Microprost Controller & lt; ApplicationController def @micropost = current_member.microposts.build (params [: micropost]) @webpage = webpage.find (params ['webpage_id']) @ micropost.webpage = @ webpage if @ microfost. Save flash [: success] = " Microfost created! " Redirect_to root_path else @feed_items = [] Render 'Page / Home' and End End and from the webpage 'Show' view:
& lt; Table class = "front" summary = "sign-in member" & gt; & Lt; TR & gt; & Lt; Td class = "main" & gt; & Lt; H1 class = "micropost" & gt; What is happening? & Lt; / H1> & Lt;% = form_for @micropost do | F | | & Gt%; & Lt;% = Render 'shared / error_messages',: object = & gt; F.object% & gt; & Lt; Div class = "field" & gt; & Lt;% = f.text_area: content% & gt; & Lt; Input type = "hidden" id = "webpage_id" name = "microprost [webpage_id]" value = "& lt;% = @ webpage.id%>" /> & Lt; / Div & gt; & Lt; Div class = "verb" & gt; & Lt;% = f.submit "Submit"%> & Lt; / Div & gt; & Lt;% end% & gt; & Lt; / TD & gt; & Lt; / TR & gt; & Lt; / Table & gt; When I save the form, I receive this error:
"The webpage could not be found without the ID"
When I Removes the context of the webpage with the form, successfully saves the form and sets the user_id field - so it is working fine (but obviously in this case the webpage_id is tap).
Where am I going wrong?
Cheers,
Dmo
ensuring dump params For that webpage_id is actually passing.
Add to your view:
& lt;% = debug params% & gt;
Comments
Post a Comment