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) %>
<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
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:> 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) %> > <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 >-- Greg Freemyer The Norcross Group Forensics for the 21st Century
Greg Freemyer wrote:> 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.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.
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
On Mar 15, 2006, at 3:46 PM, Mark Reginald James wrote:
> Greg Freemyer wrote:
>
>> 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.
>
> 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.
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2413 bytes
Desc: not available
Url :
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060316/d1072369/smime-0001.bin
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.
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:> 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 > > > > On Mar 15, 2006, at 3:46 PM, Mark Reginald James wrote: > > > Greg Freemyer wrote: > > > >> 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. > > > > 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. > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >-- Greg Freemyer The Norcross Group Forensics for the 21st Century