我正在尝试为向导实现“邪恶”gem,但我一生都无法弄清楚这个错误。已经参考了Ryan bates railscast #346和 schneems 的分步教程。
我有 2 个控制器:Weddings 和 Wedding_steps。用户最初创建了一个婚礼,在创建操作被重定向到 Wedding_steps 控制器(它使用 Wicked)后,使用附加信息更新婚礼模型。
在第一步weddingdetails中成功检测到了wedding_id,但是在提交该步骤后,我收到以下错误:
错误
ActiveRecord::RecordNotFound 在WeddingStepsController#update
找不到没有 ID 的婚礼:app/controllers/wedding_steps_controller.rb:11:in `update'
参数:
{"utf8"=>"✓", "_method"=>"put", "authenticity_token"=>"JMd+8gf4rVqOSNMSFrKcD3WxK+X3zvYliSMWqTg0SkE=", "wedding"=>{"bridename"=>"", "groomname "=>"", "weddingdate"=>"", "weddingcity"=>"", "weddingstate"=>"", "url"=>""}, "commit"=>"Next", "id "=>"wedding_id=11"}
它应该继续进行下一步/wedding_steps/eventdetails?wedding_id=11
,而是给出错误并转到/wedding_steps/wedding_id=11
另外值得注意的是,如果没有更新操作,信息会成功保存并重定向到婚礼表演操作。
以下是相关代码:
婚礼步骤控制器.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
婚礼控制器.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
第 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) %>
第 2 步:wedding_steps/eventdetails.html.erb
EVENT DETAILS STEP <!--PLACEHOLDER FOR NOW -->
路由.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'