我一直试图弄清楚一些代码.我有一个表格,我正在尝试使用Wicked和Cocoon宝石.一切正常,包括link_to_add_association功能.我正在为Cocoon推荐的相关表单字段渲染部分,并且除了link_to_remove_association函数之外,一切似乎都在找工作.它返回以下错误:
new_record?nil的未定义方法:NilClass
这是我的部分错误:
<div class="nested-fields">
<div>
<%= f.input :address1 %>
</div>
<div>
<%= f.input :address2 %>
</div>
<div>
<%= f.input :city %>
</div>
<div>
<%= f.input :state %>
</div>
<div>
<%= f.input :postal %>
</div>
<div>
<%= link_to_remove_association "remove task", f %>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
以下是调用partial的视图:
<%= simple_form_for @vendor, url: wizard_path do |f| %>
<div id="locations">
<%= f.simple_fields_for :locations do |location| %>
<%= render 'location_fields', :f => location %>
<% end %>
<div class="links"> …Run Code Online (Sandbox Code Playgroud) 你可以在包含WickedWizard gem的控制器中使用非restful方法吗?
控制器:
class Books::BookUpdateController < ApplicationController
include Wicked::Wizard
steps :title_step, :ai_archive_step, :ai_override_step #etc
def show
...
end
def update
...
end
def waterfall
...# loads of code to set up instance variables in the view, which I don't want to have to include in the normal show action for all the wizard steps.
end
end
Run Code Online (Sandbox Code Playgroud)
路线:
resources :book_update do
member do
get 'waterfall'
... and others
end
end
Run Code Online (Sandbox Code Playgroud)
gem的版本1和更低版本允许非静态操作,但是这个解决此PR的提交强制执行步骤名称.我去这条路线的错误 http://localhost:3000/book_update/3949/waterfall是
Wicked::Wizard::InvalidStepError in Books::BookUpdateController#waterfall …Run Code Online (Sandbox Code Playgroud) 好吧,所以我真的不了解邪恶的宝石中的嵌套路由.
到目前为止,我有这个.我不确定是否所有内容都在正确的文件夹中,或者我是否正确.
的routes.rb
resources :events
resources :events do
resources :build, controller: 'events/build'
end
Run Code Online (Sandbox Code Playgroud)
控制器/ 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
Run Code Online (Sandbox Code Playgroud)
控制器/活动/ 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
Run Code Online (Sandbox Code Playgroud)
意见/编译/ details.html.erb
<%= form_for @event do |f| %>
#blab blah
<% end %>
Run Code Online (Sandbox Code Playgroud)
我一开始event_build_path没有参数,我有这个错误
No route …