render_component different from link_to options

This one got me stuck for about an hour. I couldn’t figure out why this wasn’t calling the method of the component, but it was rendering the view of the component.

render_component :controller => "poll", :action => :show, :id => @event.poll

It ends up that this would be all fine and dandy if it was a call to link_to() rather than render_component even though the nature of the parameters is practically the same. So for render_component(), it should be:

render_component :controller => "poll", :action => "show", :id => @event.poll.id

it needs strings instead of symbols for :action, and it doesn’t convert an ActiveRecord object to its id–it needs to be explicitly stated.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s