I am attempting to create a login system. My UserController has this to control the new action:
def new
@user = User.new
respond_to do |format|
format.json { render :json => @user }
format.html
end
end
and my routes.rb has this to link:
resources :user
The View’s form to create a new user is this:
<%= form_for @user do |f| %>
however, I receive an Action Controller error with this:
undefined method `users_path' for #<#<Class
What has baffled me is why it is using users_path. This is a plural reference to my route. Why is it returning a plural error of user_path?? When I route `resources :users’ it clears the error, but of course I don’t have anything setup for that resource and thus produces other errors.
resources :usersis actually the correct structure, since it is a collection of users, not a single user. The route construction also expects a plural path (IIRC, it expects a plural path unless it finds aresource, as opposed toresourcesroute), hence the attempt to useusers_path.Passing an explicit url parameter is another option
<%= form_for @user, :url => user_path do |f| %>, since you already have things expecting singular routes