邪恶的宝石在更新操作中找不到婚礼 ID
[英] Wicked gem cannot find wedding ID in update action
本文介绍了邪恶的宝石在更新操作中找不到婚礼 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试为巫师实现Wicked" gem,但终生无法弄清楚这个错误.已经参考了 Ryan bates railscast #346 和 schneems 的分步教程.
我有 2 个控制器:Weddings 和 Wedding_steps.用户最初创建了一个婚礼,然后在创建操作被重定向到 Wedding_steps 控制器(使用 Wicked)以使用附加信息更新婚礼模型.
在第一步weddingdetails中成功检测到了wedding_id,但是提交该步骤后,出现以下错误:
错误
<块引用>
ActiveRecord::RecordNotFound in WeddingStepsController#update
无法找到没有 ID 的婚礼:app/controllers/wedding_steps_controller.rb:11:in `update'
参数:
{utf8"=>✓",_method"=>put","authenticity_token>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>,婚礼"=>{新娘姓名"=>",新郎姓名"=>",婚礼日期"=>",weddingcity"=>",婚礼状态"=>","url"=>>""},提交"=下一步",id"=>wedding_id=11"}
它应该继续下一步 /wedding_steps/eventdetails?wedding_id=11
而是给出错误并转到 /wedding_steps/wedding_id=11
>
另外值得注意的是,如果没有更新操作,信息会成功保存并重定向到婚礼秀操作.
相关代码如下:
wedding_steps_controller.rb
class WeddingStepsController <应用控制器包括 Wicked::Wizard步骤 :weddingdetails, :eventdetails高清秀@wedding = Wedding.find(params[:wedding_id])渲染向导结尾定义更新@wedding = Wedding.find(params[:wedding_id])@wedding.update_attributes(params[:wedding])渲染向导@wedding结尾结尾
weddings_controller.rb
def 创建@wedding = current_user.weddings.new(params[:wedding])response_to do |格式|如果@wedding.saveformat.html { redirect_towedding_steps_path(:id =>weddingdetails", :wedding_id =>@wedding.id) }format.json { 渲染 json: @wedding, 状态: :created, location: @wedding }别的format.html { 渲染动作:新";}format.json { 渲染 json: @wedding.errors, 状态: :unprocessable_entity }结尾结尾结尾
第 1 步:wedding_steps/weddingdetails.html.erb
<%= simple_form_for(@wedding, :url => Wizard_path(wedding_id: @wedding.id), :method => :put, html: { class: 'form-horizontal'})做 |f|%><%= f.error_notification %><div class="form-inputs"><div class="formrow center"><%= f.input :bridename, placeholder: "The Bride's Name", label: false %><h2 class="inline">&</h2><%= f.input :groomname, placeholder: "The Groom's Name", label: false %>
<div class="formrow center"><%= f.text_field :weddingdate %><!-- OLD STYLE DATE FORMAT <%= f.input :weddingdate, label: Wedding Date"%>--><%= f.input :weddingcity, label: City";%><%= f.input :weddingstate, label: State";%>
<div class="formrow center"><%= f.input :url, placeholder: "即'johnandkate' ", 标签: false %>
<div class="form-actions center"><%= f.button :submit, value: Next"%>
<%结束%><%= link_to 'skip', next_wizard_path(wedding_id: @wedding.id) %>
第 2 步:wedding_steps/eventdetails.html.erb
活动详情步骤 <!--PLACEHOLDER FOR NOW -->
Routes.rb
Jobshop::Application.routes.draw 做资源:别针资源:婚礼资源:wedding_steps获取用户/节目"根:到 =>'页面#home'得到关于"=>'页面#关于'devise_for :admin_users, ActiveAdmin::Devise.configActiveAdmin.routes(self)资源:邀请请求devise_for :viewsActiveAdmin.routes(self)设计为:用户ActiveAdmin.routes(self)匹配 'users/:id' =>'用户#show'
解决方案
这一行:
<%= simple_form_for(@wedding, :url => Wizard_path, :method => :put, html: { class: 'form-horizontal'}) do |f|%>
应该是:
<%= simple_form_for(@wedding, :url => Wizard_path(wedding_id: @wedding.id), :method => :put, html: { class: 'form-horizontal'})做 |f|%>
注意 wizard_path(wedding_id: @wedding.id)
当您提交表单时,您应该看到 parameters = {:wedding_id =>some_number}
在日志中.
如果更新操作不起作用,请粘贴 params
的输出.
您应该将 ":wedding_id"
作为所需 url 的一部分,这将使得甚至无法生成指向该控制器的链接,除非它具有正确格式的 url.
替换这个
资源:wedding_steps
有了这个
作用域 "weddings/:wedding_id" 做资源:wedding_steps结尾
所以现在正确的 url 看起来像 weddings/83/wedding_steps/weddingdetails
.可能您的一个或多个视图助手没有正确地包含wedding_id,并且使用此新约束,您将在视图中引发错误,但这是一件好事,因为它会向您显示格式错误的链接所在的位置.
I'm trying to implement the 'Wicked' gem for wizards and cannot figure out this error for the life of me. Already referenced Ryan bates railscast #346 and the step by step tutorial by schneems.
I have 2 controllers: Weddings and Wedding_steps. The user initially creates a Wedding and after the create action is redirected to the Wedding_steps controller (which uses Wicked) to update the wedding model with additional info.
The wedding_id is successfully detected in the first step weddingdetails, but after submitting that step, I get the following error:
ERROR
ActiveRecord::RecordNotFound in WeddingStepsController#update
Couldn't find Wedding without an ID:
app/controllers/wedding_steps_controller.rb:11:in `update'
Parameters:
{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"JMd+8gf4rVqOSNMSFrKcD3WxK+X3zvYliSMWqTg0SkE=",
"wedding"=>{"bridename"=>"",
"groomname"=>"",
"weddingdate"=>"",
"weddingcity"=>"",
"weddingstate"=>"",
"url"=>""},
"commit"=>"Next",
"id"=>"wedding_id=11"}
It is supposed to continue to the next step /wedding_steps/eventdetails?wedding_id=11
but instead gives the error and goes to /wedding_steps/wedding_id=11
Also of note is that without the Update action in place, the information successfully saves and redirects to the Wedding Show action.
Here is the relevant code:
wedding_steps_controller.rb
class WeddingStepsController < ApplicationController
include Wicked::Wizard
steps :weddingdetails, :eventdetails
def show
@wedding = Wedding.find(params[:wedding_id])
render_wizard
end
def update
@wedding = Wedding.find(params[:wedding_id])
@wedding.update_attributes(params[:wedding])
render_wizard @wedding
end
end
weddings_controller.rb
def create
@wedding = current_user.weddings.new(params[:wedding])
respond_to do |format|
if @wedding.save
format.html { redirect_to wedding_steps_path(:id => "weddingdetails", :wedding_id => @wedding.id) }
format.json { render json: @wedding, status: :created, location: @wedding }
else
format.html { render action: "new" }
format.json { render json: @wedding.errors, status: :unprocessable_entity }
end
end
end
STEP 1: wedding_steps/weddingdetails.html.erb
<%= simple_form_for(@wedding, :url => wizard_path(wedding_id: @wedding.id), :method => :put, html: { class: 'form-horizontal'}) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<div class="formrow center">
<%= f.input :bridename, placeholder: "The Bride's Name", label: false %>
<h2 class="inline"> &</h2>
<%= f.input :groomname, placeholder: "The Groom's Name", label: false %>
</div>
<div class="formrow center">
<%= f.text_field :weddingdate %>
<!-- OLD STYLE DATE FORMAT <%= f.input :weddingdate, label: "Wedding Date" %> -->
<%= f.input :weddingcity, label: "City" %>
<%= f.input :weddingstate, label: "State" %>
</div>
<div class="formrow center">
<%= f.input :url, placeholder: "i.e. 'johnandkate' ", label: false %>
</div>
</div>
<div class="form-actions center">
<%= f.button :submit, value: "Next" %>
</div>
<% end %>
<%= link_to 'skip', next_wizard_path(wedding_id: @wedding.id) %>
STEP 2: wedding_steps/eventdetails.html.erb
EVENT DETAILS STEP <!--PLACEHOLDER FOR NOW -->
Routes.rb
Jobshop::Application.routes.draw do
resources :pins
resources :weddings
resources :wedding_steps
get "users/show"
root :to => 'pages#home'
get 'about' => 'pages#about'
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
resources :inviterequests
devise_for :views
ActiveAdmin.routes(self)
devise_for :users
ActiveAdmin.routes(self)
match 'users/:id' => 'users#show'
解决方案
This line:
<%= simple_form_for(@wedding, :url => wizard_path, :method => :put, html: { class: 'form-horizontal'}) do |f| %>
Should be:
<%= simple_form_for(@wedding, :url => wizard_path(wedding_id: @wedding.id), :method => :put, html: { class: 'form-horizontal'}) do |f| %>
Note the wizard_path(wedding_id: @wedding.id)
When you submit the form you should see parameters = {:wedding_id => some_number}
in the logs.
Paste the output of the params
for the update action if it doesn't work.
Edit:
You should have ":wedding_id"
as part of the required url this will make it impossible to even generate a link to that controller unless it has a properly formatted url.
Replace this
resources :wedding_steps
with this
scope "weddings/:wedding_id" do
resources :wedding_steps
end
So now a correct url would look like weddings/83/wedding_steps/weddingdetails
. Likely one or more of your view helpers isn't including wedding_id properly and with this new constraint you will raise an error in the view, but this is a good thing since it will show you where the malformed link is.
这篇关于邪恶的宝石在更新操作中找不到婚礼 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!