Passing params to a component

I see from
http://rubyonrails.org/api/classes/ActionController/Components.html

that is possible to pass paramaters to a component.

I don’t understand the exact syntax.

I’m trying:
@master_id = @params[‘master_id’]
in the components controller but it is not working.

==== Details:
In my calling view I have:

<%= h(@opportunity.id) %>


<%= render_component :controller => “todos”, :params => {
“master_id” => @opportunity.id } %>

The above displays @opportunity.id so I know it is a valid variable.

The components (todos) controller has:
def list
@master_id = @params[‘master_id’]
@todos = Todo.find :all
render :layout => false
end

Which is my attempt to instantiate and load @master_id.

The todos list view has a simple debug display of:

<%= h(@master_id) %>

Nothing is being displayed by the above.


Greg F.
The Norcross Group
Forensics for the 21st Century

Resolved.

I switched to using a session variable.

ie. session[:case_id] = params[:case_id] etc.

It is working for me now and even better only the detail records
associated with my master are showing up. That took a little more
code, but not bad at all.

Greg

On 3/15/06, Greg F. [email protected] wrote:

==== Details:
The components (todos) controller has:
<%= h(@master_id) %>

Nothing is being displayed by the above.


Greg F.
The Norcross Group
Forensics for the 21st Century


Greg F.
The Norcross Group
Forensics for the 21st Century

If I call render_component from within a view, what would be the
appropriate way to have that call pass along any necessary data to
the controller that needs it? :params => {“var” =>
@needed_instance_var} ??

Michael J.
[email protected]

Michael J. wrote:

If I call render_component from within a view, what would be the
appropriate way to have that call pass along any necessary data to the
controller that needs it? :params => {“var” => @needed_instance_var} ??

Yes.


We develop, watch us RoR, in numbers too big to ignore.

If your component happens to be generated from the ajax_generator then
I found that I needed to catch the param ASAP in the controller and
save it out as a session variable.

Then the list / new /create methods could retrieve it from the session
variable.

ie. session[:var] = params[:var] if I recall the syntax correctly

Greg

On 3/15/06, Michael J. [email protected] wrote:

On Mar 15, 2006, at 3:46 PM, Mark Reginald J. wrote:

The components (todos) controller has:
If you want to call the component’s “list” method rather than


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Greg F.
The Norcross Group
Forensics for the 21st Century

Greg F. wrote:

The components (todos) controller has:
<%= h(@master_id) %>

Nothing is being displayed by the above.

If you want to call the component’s “list” method rather than
“index” you have to add an “:action => ‘list’” option to your
render_component call.


We develop, watch us RoR, in numbers too big to ignore.