Forum: Ruby on Rails Passing params to a component

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
25bbc96d9c53647354cb724e744b2222?d=identicon&s=25 Greg Freemyer (Guest)
on 2006-03-15 19:23
(Received via mailing list)
I see from
http://rubyonrails.org/api/classes/ActionControlle...

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) %>
        <div id="todo_list">
  <%= render_component :controller => "todos", :params => {
"master_id" => @opportunity.id } %>
        </div>

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 Freemyer
The Norcross Group
Forensics for the 21st Century
25bbc96d9c53647354cb724e744b2222?d=identicon&s=25 Greg Freemyer (Guest)
on 2006-03-16 00:46
(Received via mailing list)
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 Freemyer <greg.freemyer@gmail.com> wrote:
> ==== Details:
> The components (todos) controller has:
> <%= h(@master_id) %>
>
> Nothing is being displayed by the above.
>
>
> --
> Greg Freemyer
> The Norcross Group
> Forensics for the 21st Century
>


--
Greg Freemyer
The Norcross Group
Forensics for the 21st Century
C64e63b70be7dfed8b0742540b8b27e5?d=identicon&s=25 Mark Reginald James (Guest)
on 2006-03-16 00:49
(Received via mailing list)
Greg Freemyer 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.
E4e7d8a7b40e4c791c9263e42b8cc9a3?d=identicon&s=25 Michael Jurewitz (Guest)
on 2006-03-16 01:01
(Received via mailing list)
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 Jurewitz
sinjin5@mac.com
C64e63b70be7dfed8b0742540b8b27e5?d=identicon&s=25 Mark Reginald James (Guest)
on 2006-03-16 01:26
(Received via mailing list)
Michael Jurewitz 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.
25bbc96d9c53647354cb724e744b2222?d=identicon&s=25 Greg Freemyer (Guest)
on 2006-03-16 02:26
(Received via mailing list)
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 Jurewitz <sinjin5@mac.com> wrote:
> On Mar 15, 2006, at 3:46 PM, Mark Reginald James wrote:
> >> The components (todos) controller has:
> > If you want to call the component's "list" method rather than
>
>
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>
>


--
Greg Freemyer
The Norcross Group
Forensics for the 21st Century
This topic is locked and can not be replied to.