誰かが助けてくれることを望みます。私は他の "param is missing"という質問を通して検索してきましたが、何が間違っているのか分からないようです。私のルートでなぜ強いparamsが機能しないのかわかりません - paramが見つからないか、値が空です。
私は、このネストされたリソース「アクション」を持っているファイル
resources :jobs do
resources :actions
end
関連するモデル。 "action_reference"を無視してください。それは別のものです。
class Job < ActiveRecord::Base
has_many :actions
end
class Action < ActiveRecord::Base
belongs_to :job
belongs_to :action_reference
end
そして私は
button_to使用してPOSTリクエストを行うことで、新しいアクションを作成しようとしている。ここActionsController
class ActionsController < ApplicationController
before_action :set_job
before_action :set_action, only: [:show, :edit, :update]
# GET /jobs/:job_id/actions/:id
def show
end
# GET /jobs/:job_id/actions/new
def new
@action = Action.new
end
# GET /jobs/:job_id/actions/:id/edit
def edit
end
# POST /jobs/:job_id/actions/
def create
@action = @job.actions.create(action_params)
if @action.save
flash[:success] = "Next step successfully added."
redirect_to jobs_path
else
flash[:danger] = @action.errors.full_messages.join(", ")
redirect_to new_job_action_path
end
end
# PATCH to /jobs/:job_id/actions/:id
def update
if @action.update(action_params)
flash[:success] = "Next step successfully updated."
redirect_to jobs_path
else
flash[:danger] = @action.errors.full_messages.join(", ")
redirect_to edit_job_action_path
end
end
private
def set_job
@job = Job.find(params[:job_id])
end
def set_action
@action = Action.find(params[:id])
end
def action_params
params.require(:action).permit(:action_reference_id, :job_id, :completed_at, :next_action_date)
end
end
だとここで私のbutton_toは私が
<%= button_to answer[:text], post_action_jobs_path(@job), method: "post", params: { action: { action_reference_id: answer[:action_reference_id], job_id: @job_id , completed_at: answer[:action_completed_at], next_action_date: answer[:next_action_date] } }, type: "button", class: "btn btn btn-info btn-block" %>
です問題が私がpost_action_jobs_pathに渡している引数と何か関係があることを知っている彼は私がコントローラーのaction_paramsに渡しているものを見ていますが、私はそれを理解することはできません。
私はこれを実行すると、私はエラーを取得する:
undefined method `permit' for "create":String Did you mean? print
あなたが何か他のものを使用する必要がありますので、私は、「アクション」は、Railsのでは予約語であることについて何かを言って少し前、いくつかのスレッドを見ましたが、それが本当なら、私はそれについてどうやって行くのか分からない。
任意の助けをいただければ幸いです:)