Topic: How to use "render"

Can I use Render with parameters like this?

render :action=>'show', :id=>@photo.id

By the way, when I was using:
redirect_to :controoler =>'photos', :action => "show", :id => @photo.id

The error message is:

NoMethodError in Photos#list
Showing app/views/photos/list.rhtml where line #25 raised:

undefined method `redirect_to' for #<#<Class:0x88ab92c>:0x88ab904>

Extracted source (around line #25):

22:                                                          :url => {:action=> :show_photo},
23:                                                          :frequency => 2.0 %>
24:                                 <% else %>
25:                                     <% redirect_to :controller => 'photos', :action => "show", :id => @photo.id %>
26:                                 <% end %>
27:                             </div>
28:

It is so strange.
Thanks

Re: How to use "render"

Nope, AFAIK you cannot pass any parameters to the render call (like :id).

The reason you are getting an error is you are attempting to redirect inside the view/template file. All redirects should be done in the controller action.

Railscasts - Free Ruby on Rails Screencasts

Re: How to use "render"

Yes, but how can I pass parameters when I use "render" please?

Re: How to use "render"

If you are rendering a partial, you can pass variables using the :locals parameter:

<%= render :partial => 'item', :locals => { :foo => foo } %>

Then the "foo" variable will be usable inside the partial.

Railscasts - Free Ruby on Rails Screencasts

Re: How to use "render"

Thanks a lot.
It is working.