Nasir Khan
2006-Oct-04 15:47 UTC
problem passing parameters to a shared template from controller
I am using a shared template from within another template AND also using the same from a controller action. It works fine when called from the template BUT when called from the controller the parameter is not passed in from the controller. the controller action is - def update @picture = Picture.find(params[:id]) render(:template=>"shared/trip", "image" => @picture) end and the shared template is - trip.rhtml <div class="plank"> <img src=/images/myimages/<%= image.file_name -%> width="80" height="60"></div> The template is invoked but the image variable within the template is nil. ........... You have a nil object when you didn''t expect it! The error occured while evaluating nil.file_name ......... Thanks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Nasir Khan
2006-Oct-05 04:27 UTC
Re: problem passing parameters to a shared template from controller
I tried further.. So it works if I set a attribute before calling from the controller action. def update @picture = Picture.find(params[:id]) *@image = @picture * render :template=>"shared/trip" end The problem now is that the same shared template is called from another template <%= render "shared/trip", { "image"=>image_pp } %> now inside trip.rhtm (the shared template) I have access to image by @image (attribute) if called from controller and by simple argument "image" (no @) if called from another template. Is there no way to pass a variable just like I do from a template? Thanks in advance. On 10/4/06, Nasir Khan <rubylearner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > I am using a shared template from within another template AND also using > the same from a controller action. > It works fine when called from the template BUT when called from the > controller the parameter is not passed in from the controller. > > the controller action is - > > def update > @picture = Picture.find(params[:id]) > render(:template=>"shared/trip", "image" => @picture) > end > > and the shared template is - trip.rhtml > > <div class="plank"> > <img src=/images/myimages/<%= image.file_name -%> width="80" > height="60" > > </div> > > The template is invoked but the image variable within the template is nil. > > ........... > You have a nil object when you didn''t expect it! > The error occured while evaluating nil.file_name > ......... > > Thanks > >-- I don''t like $_, actually the only place I like $s is in my wallet. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---