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.
Greg F. (Guest)
on 2006-03-15 20: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 F.
The Norcross Group
Forensics for the 21st Century
Greg F. (Guest)
on 2006-03-16 01: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 F. <removed_email_address@domain.invalid> 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
Mark Reginald J. (Guest)
on 2006-03-16 01:49
(Received via mailing list)
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.
Michael J. (Guest)
on 2006-03-16 02: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 J.
removed_email_address@domain.invalid
Mark Reginald J. (Guest)
on 2006-03-16 02:26
(Received via mailing list)
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.
Greg F. (Guest)
on 2006-03-16 03: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 J. <removed_email_address@domain.invalid> 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
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>
>


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