Pab
2011-Aug-31 09:53 UTC
undefined method `model_name'' for NilClass:Class in rails 3.0.0
Hi, i got search which shows following error ActionView::Template::Error (undefined method `model_name'' for NilClass:Class): 1: <%= form_for(@employee) do |e| %> 2: EMP ID<%= e.text_field :id %><br> 3: <%= e.submit ''search'', :controller => ''employees'', :action => ''search1'' %> 4: <% end %> in my search action i dint provide anything like def search end if i use <%= form_for(:employee) do |e| %> it shows no error but the data is moving in to my "show" action could any one provide me a soultion ? -- 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.
Jim Ruther Nill
2011-Aug-31 12:16 UTC
Re: undefined method `model_name'' for NilClass:Class in rails 3.0.0
On Wed, Aug 31, 2011 at 5:53 PM, Pab <prabu.net88-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > > i got search which shows following error > > ActionView::Template::Error (undefined method `model_name'' for > NilClass:Class): >i think this happens when @employee is nil. double check that @employee is not nil.> 1: <%= form_for(@employee) do |e| %> > 2: EMP ID<%= e.text_field :id %><br> > 3: <%= e.submit ''search'', :controller => ''employees'', :action => > ''search1'' %> > 4: <% end %> > in my search action i dint provide anything like > def search > end > > if i use <%= form_for(:employee) do |e| %> > it shows no error but the data is moving in to my "show" action > > could any one provide me a soultion ? > > -- > 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. > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.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-/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.
Pab
2011-Sep-02 05:08 UTC
Re: undefined method `model_name'' for NilClass:Class in rails 3.0.0
Hi Jim, I got nothing in my action search and linked the search button to search1 action, which contains the find function is that a problem? thanks, -pab -- 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.
7stud --
2011-Sep-02 05:58 UTC
Re: undefined method `model_name'' for NilClass:Class in rails 3.0.0
Pab wrote in post #1019703:> Hi Jim, > > > > I got nothing in my action search and linked the search button to > search1 action, which contains the find function is that a problem? >Yes. Here is the order of what happens: 1) The browser sends a request that hits the action connected to your view. 2) The action executes and the view containing your form is processed by rails and sent to the browser. 3) All variables in your app and their values are destroyed. 4) The user fills out the form and clicks the submit button, which sends the request to your search1 action, causing the code in search1 to execute. So any code in the search1 action executes long after rails processes the view. In your view, you referenced the @employee variable, so that view''s action has to assign a value to @employee. -- 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-/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.
Pab
2011-Sep-02 09:30 UTC
Re: undefined method `model_name'' for NilClass:Class in rails 3.0.0
Hi, def search end def search1 @employee = Employee.find(params[:id]) respond_to do |format| format.html{render :partial => ''show''} format.xml end end search.html is <%= form_for(@employee) do |e| %> EMP ID<%= e.text_field :id %><br> <%= e.submit ''search'', :controller => ''employees'', :action => ''search1'' %> <% end %> problem is its not showing up search page itself thanks, -pab -- 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.
Jim Ruther Nill
2011-Sep-02 10:08 UTC
Re: Re: undefined method `model_name'' for NilClass:Class in rails 3.0.0
On Fri, Sep 2, 2011 at 5:30 PM, Pab <prabu.net88-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > > def search > > end > > > > def search1 > > @employee = Employee.find(params[:id]) > respond_to do |format| > format.html{render :partial => ''show''} > format.xml > end > > end > > > > > > search.html is > <%= form_for(@employee) do |e| %> > EMP ID<%= e.text_field :id %><br> > <%= e.submit ''search'', :controller => ''employees'', :action => > ''search1'' %> > <% end %> > >the search method doesn''t declare any instance variable but in the view template, you want to use @employee. form_for expects @employee to be declared so that form_for can form the url and the input field names. so the solution to your problem is to just declare an @employee in the search action.> > > problem is its not showing up search page itself > > > thanks, > -pab > > -- > 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. > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.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-/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.
Pab
2011-Sep-02 10:31 UTC
Re: undefined method `model_name'' for NilClass:Class in rails 3.0.0
hi def search @employee end i have done the above, but it shows following error undefined method `model_name'' for NilClass:Class Extracted source (around line #1): 1: <%= form_for(@employee) do |e| %> 2: <%= e.error_msg %> 3: EMP ID<%= e.text_field :id %><br> 4: <%= e.submit ''search'', :controller => ''employees'', :action => ''search1'' %> thanks, -pab -- 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.
Jim Ruther Nill
2011-Sep-02 10:42 UTC
Re: Re: undefined method `model_name'' for NilClass:Class in rails 3.0.0
On Fri, Sep 2, 2011 at 6:31 PM, Pab <prabu.net88-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hi > > def search > @employee > end > > i have done the above, but it shows following error > > undefined method `model_name'' for NilClass:Class > > Extracted source (around line #1): > > 1: <%= form_for(@employee) do |e| %> > 2: <%= e.error_msg %> > 3: EMP ID<%= e.text_field :id %><br> > 4: <%= e.submit ''search'', :controller => ''employees'', :action => > ''search1'' %> > >you need to set @employee to something, not just declare it like that in the controller. @employee = Employee.new #or some other model> > thanks, > -pab > > -- > 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. > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.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-/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.
Pab
2011-Sep-02 11:00 UTC
Re: undefined method `model_name'' for NilClass:Class in rails 3.0.0
Hi, in @employee = Employee.new, what .new describes about? and i gave @employee = Employee.search instead of that, which result in error undefined method `search'' for #<Class:0x9295500> thanks, -pab -- 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.
Jim Ruther Nill
2011-Sep-02 11:44 UTC
Re: Re: undefined method `model_name'' for NilClass:Class in rails 3.0.0
On Fri, Sep 2, 2011 at 7:00 PM, Pab <prabu.net88-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > in @employee = Employee.new, what .new describes about? and i gave > @employee = Employee.search > instead of that, which result in error > > undefined method `search'' for #<Class:0x9295500> > >I suggest you read some tutorials first Pab> > thanks, > -pab > > -- > 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. > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.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-/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.