Reputation: 23
I know this question been ask before and they said 'models are independent of the controller.' So, following my same code I did for other models I just renamed my working code to fit to my new model. But I'm getting an error undefined method 'userimages_path'
Here the code I'm using.
The model is userimage
and the controller is uploads
.
Controller/uploads_controller.rb
def new
@userimage = Userimage.new
end
Model/userimage.rb is an empty file
Views/uploads/new.html.erb (This line is throwing the error.)
<%= form_for @userimage do |f|%>
In my routes.rb
resources :uploads
I have rake db:migrate
several times to make sure I did migrate the database thinking this might be why it can't find the Userimage
.
What I have I done wrong/missing here?
Upvotes: 1
Views: 1104
Reputation: 44380
It is a Rails magic, when you don't specify second option(url
) for form_for
, Rails try to set it, in your case <%= form_for @userimage do |f|%>
converts by Rails to <%= form_for @userimage, url: userimages_path do |f|%>
, in your routes, there is no such _path
helper.
To resolve this issue run bundle rake routes
and set the right url
option.
Upvotes: 1
Reputation: 4427
try below code:
<%= form_for @userimage, url: "/uploads" do |f|%>
def create
...
end
Upvotes: 0