ruby on rails - Undefined method 'errors' for nil:NilClass -


i'm following this tutorial on authentication in rails , i'm encountering issue on html signup form :

undefined method errors nil:nilclass

to line : <% if @user.errors.any? %>.

i searched lot on internet , tried lot of things, cannot make work.

here view :

<%= form_for(:user, :url => {:controller => 'users', :action => 'create'}) |f| %>   <input class="col-lg-4 col-lg-offset-4" type="text" placeholder="email" size="6"></br>   <input class="col-lg-4 col-lg-offset-4" type="password" placeholder="password" size="6"></br>   <input class="col-lg-4 col-lg-offset-4" type="password" placeholder="password confirmation" size="6"></br>   <%= f.submit %><div id="valid"><input class="col-lg-4 col-lg-offset-4" type="submit" value="sign up"/></div>   <button type="button" class="btn btn-link col-lg-4 col-lg-offset-4"><%=link_to "already registered ?", home_path%></button> <% end %> <% if @user.errors.any? %> // error line    <ul class="signup_errors">   <% message_error in @user.errors.full_messages %>     <li>* <%= message_error %></li>   <% end %>   </ul> <% end %> 

my controller :

class userscontroller < applicationcontroller   def new     @user = user.new   end    def create     @user = user.new(params[:user])     if @user.save       flash[:notice] = "you signed successfully"       flash[:color]= "valid"     else       flash[:notice] = "form invalid"       flash[:color]= "invalid"     end     render "new"   end end 

and route :

rails.application.routes.draw    root :to => 'users#home'   'home' => 'users#home'   'signup' => 'users#signup'    resources :users     post :create   end 

you need rename new action signup. in current state - rails sees template signup , assumes corresponding controller action empty, nil in instance variable, because new not being called.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -