は、だから私は、 "エントリー" そのようなユーザモデルとネストされたモデルを持っている:Rails 4:ネストされたオブジェクトを削除するにはどうすればよいですか?
user.rb
class User < ActiveRecord::Base
has_many :entries
...
end
entry.rb
class Entry < ActiveRecord::Base
belongs_to :user
...
end
ユーザー/ show.html.erb
<p><%= link_to 'Destroy', remove_entry_path, method: :delete, data: { confirm: 'Are you sure?' } %></p>
routes.rb
resources :users do
resources :entries
end
...
delete "remove_entry" => "entries#destroy", :as => "remove_entry"
entries_controller.rb
def destroy
@user = current_user
@user.entries.find(params[:id]).destroy
respond_to do |format|
format.html { redirect_to user_path(current_user), notice: 'Entry was successfully destroyed.' }
format.json { head :no_content }
end
end
そして、私はこのエラーを取得する:この行の
はIDなしでエントリが見つかりませんでした
@user.entries.find(params[:id]).destroy
何午前私は間違っている?
私は 'paramsは思い[:ID]' 'nil' –