Rails 控制器未获取特定参数
Rails controller isn't getting specific params
我正在尝试按照邪恶的教程部分创建对象
( https://github.com/zombocom/wicked/wiki/Building-Partial-Objects-Step-by-Step )
问题是,我在创建对象本身时遇到了问题。我试过使用和不使用强参数,甚至从控制器发出调用,但都可以通过。我做错了什么?
class ProspectsController < ApplicationController
include Wicked::Wizard
steps :signup, :business_details, :user_details
def show
create_prospect if params[:prospect_id].nil?
byebug # => prospect_id is no appearing => Not_found
@prospect = Prospect.find(params[:prospect_id])
render_wizard
end
def update
@prospect = Prospect.find(params[:prospect_id])
params[:prospect][:status] = 'users_detailed' if step == steps.last
@prospect.update_attributes(params[:prospect])
render_wizard @prospect
end
def create_prospect
@prospect = Prospect.create
new_prospect_build_path(prospect_id: @prospect.id)
end
# def prospect_params
# params.require(:prospect).
# permit(:user_first_name, :user_last_name, :user_email, :dni, :plan, :empresa_name, :empresa_email,
# :empresa_phone, :empresa_address, :empresa_web, :empresa_category, :empresa_summary, :user_birthday,
# :user_phone, :user_address, :sex, :iban_code, :status, :prospect_id)
# end
end
路线:
resources :prospects, only: [:show, :update] do
resources :build, controller: 'prospects'
end
您正在对两条路线使用相同的控制器操作:
GET /prospects/:prospect_id/build/:id => prospects#show
GET /prospects/:id => prospects#show
与更新相同。
如果您将在 GET prospect_path
之前到达该控制器,您将不会得到 :prospect_id
,但会得到 :id
.
我正在尝试按照邪恶的教程部分创建对象 ( https://github.com/zombocom/wicked/wiki/Building-Partial-Objects-Step-by-Step )
问题是,我在创建对象本身时遇到了问题。我试过使用和不使用强参数,甚至从控制器发出调用,但都可以通过。我做错了什么?
class ProspectsController < ApplicationController
include Wicked::Wizard
steps :signup, :business_details, :user_details
def show
create_prospect if params[:prospect_id].nil?
byebug # => prospect_id is no appearing => Not_found
@prospect = Prospect.find(params[:prospect_id])
render_wizard
end
def update
@prospect = Prospect.find(params[:prospect_id])
params[:prospect][:status] = 'users_detailed' if step == steps.last
@prospect.update_attributes(params[:prospect])
render_wizard @prospect
end
def create_prospect
@prospect = Prospect.create
new_prospect_build_path(prospect_id: @prospect.id)
end
# def prospect_params
# params.require(:prospect).
# permit(:user_first_name, :user_last_name, :user_email, :dni, :plan, :empresa_name, :empresa_email,
# :empresa_phone, :empresa_address, :empresa_web, :empresa_category, :empresa_summary, :user_birthday,
# :user_phone, :user_address, :sex, :iban_code, :status, :prospect_id)
# end
end
路线:
resources :prospects, only: [:show, :update] do
resources :build, controller: 'prospects'
end
您正在对两条路线使用相同的控制器操作:
GET /prospects/:prospect_id/build/:id => prospects#show
GET /prospects/:id => prospects#show
与更新相同。
如果您将在 GET prospect_path
之前到达该控制器,您将不会得到 :prospect_id
,但会得到 :id
.