你好,我得到了错误:缺少参数或值为空:运动
我有一个创建新活动的链接:
<%= button_to 'Start 14 days free trial', select_campaign_type_path(campaign_type: 1), method: :patch, class: 'py-4 px-10 w-full text-white font-semibold rounded-xl focus:ring focus:ring-indigo-300 bg-indigo-600 hover:bg-indigo-700 transition ease-in-out duration-200' %>
我的控制器动作中:
def select_campaign_type
@campaign = current_user.campaigns.build(campaign_params)
redirect_to new_campaign_path(@campaign), status: :see_other and return if @campaign.campaign_type.blank?
respond_to do |format|
if @campaign.save
puts "Hey"
format.html { redirect_to step1_campaign_path(@campaign), status: :found }
else
format.html { render :new, status: :unprocessable_entity }
end
end
end
在我的活动参数中:
def campaign_params
params.require(:campaign).permit(:campaign, :campaign_type)
end
路线
patch :select_campaign_type, to: "campaigns#select_campaign_type", as: :select_campaign_type
如果我删除require(:campaign),那么我将得到相同的错误:utf8,_authenticity_token和:method。
1条答案
按热度按时间mm5n2pyu1#
确保在routes.rb文件中正确定义了select_campaign_type操作的路由。它应该是一个PATCH请求,指向适当的控制器和操作。