ruby on rails - undefined method user_path' form_for -


i have userscontroller , has below code

def sign_up @user = user.new end 

and view page has

<div class="col-md-6 col-md-offset-3">     <%= form_for @user |f| %>       <%= f.label :first_name%>       <%= f.text_field :first_name %>       <%= f.label :last_name %>       <%= f.text_field :last_name %>       <%= f.submit "register", class: 'btn btn-primary'%>     <% end %>   </div> 

my routes.rb file contains following entry

 'signup' => 'users#sign_up' 

but when submit form, says

actionview::template::error (undefined method `users_path' #<#<class:0x00000004d91490>:0x00000004d90220>) 

why throw error , need explicity point url in form_for?? why so??

change routes to:

resources :users, only: [:new, :create], path_names: {new: 'sign_up'} 

and rename sign_up action new. reason getting error rails trying guess correct url given resource. since have passed @user, instance of user class, try call "#{@user.class.model_name.route_key}_path key, results in error got.

to solve issue need either make routes define users_path or need specify url directly using url option. users_path can defined either index or create action, above solution work (and not create remaining crud routes, yey!)


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -