私は完全に迷っています!私はdecent_exposure gemを初めて使用しています。問題があると思います。 これはリンクですhttps://github.com/hashrocket/decent_exposure フォームを送信すると、何も保存されません。データベース内のすべてのテーブルは空のフィールドでいっぱいです。 これは、これは私のコントローラである私のフォームdecent_exposureで送信した後にオブジェクトを保存するにはどうすればよいですか?
<%= simple_form_for book do |f| %>
<%= f.input :name %>
<%= f.input :author %>
<%= f.input_field :annotation %>
<%= f.button :submit %>
<% end %>
です:
class BooksController < ApplicationController
before_filter :is_admin?
before_filter :authenticate_user!
expose(:book, finder_parameter: :id, params: :book_params)
#I've tried both expose(:book) and expose(:books)
def create
if book.save
redirect_to(book)
else
render :new
end
end
def update
if book.save
redirect_to(book)
else
render :edit
end
end
def show
end
def is_admin?
if current_user.admin?
true
else
render :text => 'Registrate'
end
end
def book_params
params.require(:book).permit(:name, :author, :annotation)
end
end
それは間違いになります
paramが存在しないか、値が空である:本
def book_params params.require(:book).permit(:name, :author, :anotation) end
paramsとbook_paramsメソッドを使わずに(:book)を公開しようとすると、大丈夫ですが、フォームを送信した後はすべてのフィールドがnilになります。私は間違って何をしていますか? params定義に間違いはありますか?私は思っていて、何度もさまざまな変種を試していますが、どこに問題があるのか想像できません。すべての助けに感謝します!
見つけました! "params::book_params"の代わりに "attribures::book_params"がありました – Jakov