我一直在跟踪邪恶的宝石https://github.com/schneems/wicked/wiki/Building-Partial-Objects-Step-by-Step的一步一步的例子,但我正在努力使其发挥作用
的routes.rb
post '/trips/building/build(.:format)', :to => "trips/build#create"
resources :trips do
resources :build, controller: 'trips/build'
end
trips_controller.rb
class TripsController < ApplicationController
include Wicked::Wizard
before_action :set_trip, only: [:show, :update]
steps :basic, :details
def show
render_wizard
end
def create
@trip = Trip.create
redirect_to wizard_path(steps.first, :trip_id => @trip.id
end
def update
@trip.update_attributes(trip_params)
render_wizard @trip
end
private
def set_trip
@trip = Trip.find(params[:trip_id])
end
def trip_params
....
end
end
index.html.erb
<%= link_to 'Create New Trip', '/trips/building/build', :method => :post, :class=>'btn btn-danger'%>
控制台中出现错误:
Started POST "/trips/building/build" for 127.0.0.1 at 2014-04-16 22:50:20 -0700
ActionController::RoutingError - uninitialized constant Trips
这让我发疯了......
有什么想法吗?
答案 0 :(得分:0)
您的控制器名称不正确 - 您的路线指向Trips::BuildController
,但您的控制器定义为TripsController
。
您共享的链接定义了Products::BuildController
,这就是它在那里工作的原因。