Hi, I have a form to add links to youtube. for that form I hide an "Add" button if the user is not logged in. I''m using a partial to insert the form. <div id="video"> <%= render :partial => "layouts/video_form" %> </div> The contents of the partial are something like: <div id="video_form" class="video_form"> <% form_for([@tab, @video]) do |f| %> ... <% if canComment() %> <%= f.submit "Add" %> <% else %> <b>Login to add videos</b> <% end %> <% end %> </div> This works fine when I run it from the main controller (called tabs). In that controller the @tab and @video objects are known. From that same page I can also log in, but the sessions are handled by a session controller, not the tab controller in which we are. So when a new session is created it instructs to render that partial again: page.replace_html ''video'', :partial => ''layouts/video_form'' And my problem is that at that point the @tab object is nil: ActionView::TemplateError (Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id) on line #2 of layouts/_video_form.html.erb: 1: <div id="video_form" class="video_form"> 2: <% form_for([@tab, @video]) do |f| %> -------- How can I avoid losing the @tab object when the partial is instructed to be inserted from a different controller? Thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-May-05 09:39 UTC
Re: Inserting partial from different controller problem
On 5 May 2008, at 10:33, comopasta Gr wrote:> > > This works fine when I run it from the main controller (called > tabs). In > that controller the @tab and @video objects are known. > > From that same page I can also log in, but the sessions are handled > by a > session controller, not the tab controller in which we are. So when a > new session is created it instructs to render that partial again: > > page.replace_html ''video'', :partial => ''layouts/video_form'' > > And my problem is that at that point the @tab object is nil: > > ActionView::TemplateError (Called id for nil, which would mistakenly > be > 4 -- if you really wanted the id of nil, use object_id) on line #2 of > layouts/_video_form.html.erb: > 1: <div id="video_form" class="video_form"> > 2: <% form_for([@tab, @video]) do |f| %> > > -------- > > How can I avoid losing the @tab object when the partial is > instructed to > be inserted from a different controller?You''re thinking about this backwards. You need to ensure that @tab and @video are defined. (eg when the user logs in remember where they cam from so you know which video to render the partial for) Fred --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Thorsten Mueller
2008-May-05 09:40 UTC
Re: Inserting partial from different controller problem
if i understand your setup right, then you can''t you have most likely a submit or redirect there for the login, so the browser requests information from the server independently of any further requests. i would advise to store this stuff in the session, but most likely you don''t have one before the login. so the only thing you can do is to explicitly load the @tab & @video in your sessions controller. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
comopasta Gr
2008-May-05 10:25 UTC
Re: Inserting partial from different controller problem
Hi, thanks for the comments. Yeah there is no session before loggin in. So if I understood correctly one way to solve this is to store where the user was when the login process fires up. I actually had to do that to improve overall navigation but I was hoping to avoid it for this. I guess now is the time to get that in place. Thanks. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
comopasta Gr
2008-May-05 10:31 UTC
Re: Inserting partial from different controller problem
>> so the only thing you can do is to explicitly load the @tab & @video in >> your sessions controller.Wait, yep I have a submit in the tabs page for the login process. So you mean that I could pass the objects there as parameters and then could load them again in the other controller so the partial can use them. This is part of the login form: <%= submit_to_remote ''commit'', ''Log in'', :url => {:action => ''create'', :controller => ''session''}, :after => "new Effect.SlideUp(''login_area'');" %> Regards. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
comopasta Gr
2008-May-05 21:01 UTC
Re: Inserting partial from different controller problem
Hi, just to close the issue here''s how I got it solved. In the form where the user logs in I pass now the tab id: <%= submit_to_remote ''commit'', ''Log in'', :url => {:action => ''create'', :controller => ''session'', :thetab => @tab} %> In the sessions controller I load the tab and build a video for it: @tab = Tab.find(params[:thetab]) @video = @tab.videos.build Now the partial rendering is able to use the right objects needed: page.replace_html ''video'', :partial => ''layouts/video_form'' It seems to work great. Thanks for the hints again! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---