Hi, I have a simple sideblog with my posts in it. I can see 5 last posts in my index action. Could I add form to submit a new post at the top of my posts? I dont know how to render new post action in my index action to show the form. THX
on 2008-11-24 11:01
on 2008-11-24 12:18
You can't render one action in another. What you should do is put the submit form in a partial (call it _form.html.erb) . See http://railscasts.com/episodes/80 for more info. In both your new and index action you put <%= render :partial => @post %>. Don't forget to instantiate @post in both your index and new controller - @post = Post.new . You ofcourse can also do this in the partial but that's not really MVCish. I hope this helps. Stijn
on 2008-11-24 15:20
Thx for your help. Could I do the same thing (:partial =>) even with another controller? I quess not. Thx. Pete
on 2008-11-25 18:13
Do you mean call a controller via :partial => ? No, that's not possible.
on 2008-11-25 18:47
All right, thanks. I have got a users and entries controller. Users homepage is www.mydomain.com/profile/:username (:controller => 'users', :action => 'show'). Users can add a new posts in (:controller => 'entries', :action => 'new') and I would like to allow users to add and see their posts at profile page, which is in users controller. Is there way out of this? Hope, yes. Thank you. Pete Tarscher wrote: > Do you mean call a controller via :partial => ? No, that's not > possible.
on 2008-11-26 11:35
Hi Pete, That's perfectly possible. in your user show view def show @entry = Entry.new end in your user show view // when using form_for @entry rails will know that your form is intended for the entries controller and will point you there automatically. form_for @entry do |f| // form elements here end Don't forget to redirect to the user show view in your entries create action. I hope this helps. Stijn
on 2008-11-26 23:21
Hi Stijn, thank you very much, it is exactly what I was hoping for. Pete