【发布时间】:2014-11-07 00:55:07
【问题描述】:
好的,所以我不太了解 wicked gem 中的嵌套路由。
到目前为止,我有这个。我不确定所有内容是否都在正确的文件夹中,或者我是否做对了。
routes.rb
resources :events
resources :events do
resources :build, controller: 'events/build'
end
控制器/events_controller.rb
def create
@event = Event.new(event_params)
if @event.save
flash[:success] = "Event Created!"
redirect_to event_build_path(event_id: "event", id: @event.id)
# previously had redirect_to event_build_path without parameters)
else
render 'new'
end
end
控制器/事件/build_controller.rb
class Events::BuildController < ApplicationController
include Wicked::Wizard
steps :details, :visibility
def show
@event = Event.find(params[:event_id])
render_wizard
end
end
views/build/details.html.erb
<%= form_for @event do |f| %>
#blab blah
<% end %>
一开始我的event_build_path 没有参数,我遇到了这个错误
No route matches {:action=>"show", :controller=>"events/build"} missing required keys: [:event_id, :id]
受到Rails wicked gem redirect with params 的影响,但不完全了解路由
我没有设置 event_id 并且我真的不明白 wicked 如何跟踪通过 id 的步骤(或者如果它的 event_id)。
由于我的对象(事件)还没有创建,“event_id”是什么,最后的id代表什么?
【问题讨论】:
标签: ruby-on-rails ruby rails-routing wicked-gem