[Rails] Passing parameters to component methods

Kim kim at tinker.com
Tue Mar 1 17:07:35 GMT 2005


On Feb 28, 2005, at 9:06 AM, Kim wrote:

> Hello,
>
> I have just upgraded to 0.10.0 and I am experimenting with packaging 
> some
> of the functionality of my web site into components.  Maybe I am 
> missing
> something obvious but I don't see any way to pass a parameter to a 
> method
> for a component.  For example, using the example from
> http://manuals.rubyonrails.com/read/chapter/73, if I wanted to pass a
> range of image ids to the recent_image method, how would I do it?  I 
> have
> looked at the source for 
> actionpack-1.5.0/lib/action_controller/components.rb
> and I don't see any provision for specifying parameters, only the 
> controller
> and action.
>
> Thanks,
> Kim
>
>

To answer my own question, I did find the obvious solution.  You can 
use the
:params symbol to pass in a hash of key/value pairs.

<%= render_component(:controller => 'gallery/image', :action => 
'recent_image', :params => { 'image_ids' => 1..10 }) %>

Kim



More information about the Rails mailing list