Igo*_*ins 7 ruby-on-rails simple-form ruby-on-rails-4
我有albums,pictures在哪里albums hasmany pictures
这是我的routes.rb
resources :albums do
resources :photos
end
Run Code Online (Sandbox Code Playgroud)
而不是photos_path我的路径是album_photos_path
在my photos/new.html.erb我得到这个错误:
undefined method photos_path' for #<#<Class:0x5232b40>:0x3cd55a0>
我怎么做而不是photos_path简单的形式写album_photos_path?
我的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 %>
Run Code Online (Sandbox Code Playgroud)
Man*_*eep 11
您可以url在表单中指定.像这样:
<%= 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 %>
Run Code Online (Sandbox Code Playgroud)
但是你的代码也应该有效.在你的新动作中你是否初始化了@album和@photo,类似于:
def new
@album = Album.new
@photo = @album.pictures.build
end
Run Code Online (Sandbox Code Playgroud)