how to render part of code in another one


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

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 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 = . You ofcourse can also do this in the
partial but that's not really MVCish.

I hope this helps.

Thx for your help. Could I do the same thing (:partial =>) even with
another controller? I quess not. Thx. Pete

Do you mean call a controller via :partial => ? No, that's not

All right, thanks. I have got a users and entries controller. Users
homepage is (: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.

Tarscher wrote:

Hi Pete,

That's perfectly possible.

in your user show view

def show
@entry =

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
form_for @entry do |f|
// form elements here

Don't forget to redirect to the user show view in your entries create

I hope this helps.

Hi Stijn,

thank you very much, it is exactly what I was hoping for.