mattyh88
2010-Oct-16 15:33 UTC
Authlogic: rendering the login form as a partial on every page of my site
Hi, I''m trying to setup the Authlogic gem. I''ve followed this tutorial: (because I''m using Rails 3) http://www.logansbailey.com/2010/10/06/how-to-setup-authlogic-in-rails-3/ All of this works. But now I''d like to render the login form as a partial on every page of my site. 1) I''ve rendered the partial in my application.html.erb file as followed: <%= render :partial => "user_sessions/form" %> 2) When I start my server and try rendering my index view of my home controller, I get the following error: undefined method `model_name'' for NilClass:Class Extracted source (around line #1): 1: <%= form_for(@user_session) do |f| %> 2: <% if @user_session.errors.any? %> 3: <div id="error_explanation"> 4: <h2><%= pluralize(@user_session.errors.count, "error") %> prohibited this user_session from being saved:</h2> 3) I figured out I had to make a new @user_session var in the action method of my controller for every view I''d like to render my login form partial on. 4) I''ve put @user_session = UserSession.new in the "new"-action-method in my home controller and so my index view rendered fine. But now I''d like to render my login form on every page of my site. Is there a way to set the @user_session for every action? Like in the application_controller? How would you do that? Thank you, Mathew -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
David Kahn
2010-Oct-16 23:41 UTC
Re: Authlogic: rendering the login form as a partial on every page of my site
On Sat, Oct 16, 2010 at 8:33 AM, mattyh88 <mathew.hucks-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I''m trying to setup the Authlogic gem. I''ve followed this tutorial: > (because I''m using Rails 3) > http://www.logansbailey.com/2010/10/06/how-to-setup-authlogic-in-rails-3/ > > All of this works. But now I''d like to render the login form as a > partial on every page of my site. > > 1) I''ve rendered the partial in my application.html.erb file as > followed: > > <%= render :partial => "user_sessions/form" %> > > 2) When I start my server and try rendering my index view of my home > controller, I get the following error: > > undefined method `model_name'' for NilClass:Class > Extracted source (around line #1): > 1: <%= form_for(@user_session) do |f| %> > 2: <% if @user_session.errors.any? %> > 3: <div id="error_explanation"> > 4: <h2><%= pluralize(@user_session.errors.count, "error") %> > prohibited this user_session from being saved:</h2> > > 3) I figured out I had to make a new @user_session var in the action > method of my controller for every view I''d like to render my login > form partial on. > > 4) I''ve put @user_session = UserSession.new in the "new"-action-method > in my home controller and so my index view rendered fine. But now I''d > like to render my login form on every page of my site. > > Is there a way to set the @user_session for every action? Like in the > application_controller? How would you do that? >You should able to do this in the application_controller: before_filter :new_user_session private def new_user_session @new_user_session = UserSession.new end Try that, should then have the @new_user_session available to you since all controllers inherit from application controller.> > Thank you, > Mathew > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
mattyh88
2010-Oct-17 09:55 UTC
Re: Authlogic: rendering the login form as a partial on every page of my site
thanks! works like a charm :) On 17 okt, 01:41, David Kahn <d...-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> wrote:> On Sat, Oct 16, 2010 at 8:33 AM, mattyh88 <mathew.hu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi, > > > I''m trying to setup the Authlogic gem. I''ve followed this tutorial: > > (because I''m using Rails 3) > >http://www.logansbailey.com/2010/10/06/how-to-setup-authlogic-in-rail... > > > All of this works. But now I''d like to render the login form as a > > partial on every page of my site. > > > 1) I''ve rendered the partial in my application.html.erb file as > > followed: > > > <%= render :partial => "user_sessions/form" %> > > > 2) When I start my server and try rendering my index view of my home > > controller, I get the following error: > > > undefined method `model_name'' for NilClass:Class > > Extracted source (around line #1): > > 1: <%= form_for(@user_session) do |f| %> > > 2: <% if @user_session.errors.any? %> > > 3: <div id="error_explanation"> > > 4: <h2><%= pluralize(@user_session.errors.count, "error") %> > > prohibited this user_session from being saved:</h2> > > > 3) I figured out I had to make a new @user_session var in the action > > method of my controller for every view I''d like to render my login > > form partial on. > > > 4) I''ve put @user_session = UserSession.new in the "new"-action-method > > in my home controller and so my index view rendered fine. But now I''d > > like to render my login form on every page of my site. > > > Is there a way to set the @user_session for every action? Like in the > > application_controller? How would you do that? > > You should able to do this in the application_controller: > > before_filter :new_user_session > > private > > def new_user_session > @new_user_session = UserSession.new > end > > Try that, should then have the @new_user_session available to you since all > controllers inherit from application controller. > > > > > > > Thank you, > > Mathew > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
suruen
2011-Sep-04 05:29 UTC
Re: Authlogic: rendering the login form as a partial on every page of my site
mattyh88 <mathew.hucks@...> writes:> > thanks! > works like a charm :) > > On 17 okt, 01:41, David Kahn <d...@...> wrote: > > On Sat, Oct 16, 2010 at 8:33 AM, mattyh88 <mathew.hu...@...> wrote: > > > Hi, > > > > > I''m trying to setup the Authlogic gem. I''ve followed this tutorial: > > > (because I''m using Rails 3) > > >http://www.logansbailey.com/2010/10/06/how-to-setup-authlogic-in-rail... > > > > > All of this works. But now I''d like to render the login form as a > > > partial on every page of my site. > > > > > 1) I''ve rendered the partial in my application.html.erb file as > > > followed: > > > > > <%= render :partial => "user_sessions/form" %> > > > > > 2) When I start my server and try rendering my index view of my home > > > controller, I get the following error: > > > > > undefined method `model_name'' for NilClass:Class > > > Extracted source (around line #1): > > > 1: <%= form_for(@user_session) do |f| %> > > > 2: <% if @user_session.errors.any? %> > > > 3: <div id="error_explanation"> > > > 4: <h2><%= pluralize(@user_session.errors.count, "error") %> > > > prohibited this user_session from being saved:</h2> > > > > > 3) I figured out I had to make a new @user_session var in the action > > > method of my controller for every view I''d like to render my login > > > form partial on. > > > > > 4) I''ve put @user_session = UserSession.new in the "new"-action-method > > > in my home controller and so my index view rendered fine. But now I''d > > > like to render my login form on every page of my site. > > > > > Is there a way to set the @user_session for every action? Like in the > > > application_controller? How would you do that? > > > > You should able to do this in the application_controller: > > > > before_filter :new_user_session > > > > private > > > > def new_user_session > > @new_user_session = UserSession.new > > end > > > > Try that, should then have the @new_user_session available to you since all > > controllers inherit from application controller. > > > > > > > > > > > > > Thank you, > > > Mathew > > > > > -- > > > 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@... > > > To unsubscribe from this group, send email to > > > > rubyonrails-talk+unsubscribe@...<rubyonrails-talk%2Bunsubscrib e <at>googlegroups.com>> > > . > > > For more options, visit this group at > > >http://groups.google.com/group/rubyonrails-talk?hl=en. >I am trying to do the same thing. I followed the same tutorial, added the @user_session = UserSession.new (tried both the home controller and application controller) but I am still getting ActionView::Template::Error (undefined method `model_name'' for NilClass:Class): 1: = form_for @user_session do |f| 2: -if @user_session.errors.any? 3: #error_explanation 4: %h2= "#{pluralize(@user_session.errors.count, "error")} prohibited this user_session from being saved:" app/views/user_sessions/_form.html.haml:1:in `_app_views_user_sessions__form_html_haml__892280163_96031200'' app/views/home/index.html.haml:6:in `_app_views_home_index_html_haml__1051594895_96219820'' Any idea how to solve this? Everything else works fine, as described in the tutorial. I am just unable to render the partial user_sessions/form from anywhere else, i.e. it''s only working from user_sessions/new. I''d appreciate any help, I''ve been struggling with this for a while and cannot figure it out. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.