Undefined method path with simple form

I have albums and pictures , where albums hasmany pictures

These are my .rb routes

  resources :albums do resources :photos end 

Instead of photos_path my path is album_photos_path In my photos/new.html.erb I get this error:

undefined method photos_path' for #<#<Class:0x5232b40>:0x3cd55a0>

How can I make a simple form write album_photos_path instead of album_photos_path ?

My new.html.erb

 <%= simple_form_for([@album, @photo]) do |f| %> <%= f.error_notification %> <div class="form-inputs"> <%= f.input :title %> <%= f.input :description %> </div> <div class="form-actions"> <%= f.button :submit %> </div> <% end %> 
+7
ruby-on-rails ruby-on-rails-4 simple-form
source share
1 answer

You can specify url in your form. Like this:

 <%= simple_form_for @photo, url: album_photos_path do |f| %> <%= f.error_notification %> <div class="form-inputs"> <%= f.input :title %> <%= f.input :description %> </div> <div class="form-actions"> <%= f.button :submit %> </div> <% end %> 

But your code should also work. In your new action, you initialized both @album and @photo, something like:

 def new @album = Album.new @photo = @album.pictures.build end 
+9
source share

All Articles