【发布时间】:2014-04-22 00:13:58
【问题描述】:
我希望在我的 web 应用程序中重用表单,我尝试使用部分表单来完成此任务。这是我试图干掉的代码:
#layouts/_form.html.haml
.col-sm-6.col-sm-offset-3.well.form-box
.col-sm-12
.row
%h1
.text-center Create a new trip.
.small.text-center
Let's get started planning your trip.
.row.top-buffer
= bootstrap_form_for(@trip, url: customers_trips_path) do |f|
= render 'shared/error_messages', object: f.object
= f.text_field :trip_name, label: "What would you like to call this trip?"
= f.select :location, options_for_select(Vendor.allowed_locations, params[:location]), label: "Where will you be going?"
= f.date_select :start_date, { :label => "What is the start date for your trip?", :start_year => Time.new.year }
= f.number_field :number_of_days, value: 1, in: 1...90, label: "How many days will you be going for?"
.center= f.submit "Create Trip", class: "btn btn-large btn-primary"
我的部分尝试如下所示:
- provide(:title, "Create a Trip")
.col-sm-6.col-sm-offset-3.well.form-box
.col-sm-12
.row
%h1
.text-center= header
.small.text-center
= slogan
.row.top-buffer
但是,当我尝试像上面那样渲染我的部分,然后将我的表单嵌套在它下面时,我收到了这个错误:
syntax error, unexpected keyword_ensure, expecting end-of-input
我很确定我做错了。我正在研究以某种方式传递 bootstrap_form_for(可能使用 Object#send?),但这似乎有点笨拙,并且想知道是否有更优雅的解决方案。
更新:我修复了对局部变量的调用,并更新了代码以反映这一点。问题仍然存在。
顺便说一句,我是这样称呼局部的。
= render 'layouts/form', header: "original", slogan: "test"
= bootstrap_form_for(@trip, url: customers_trips_path) do |f|
= render 'shared/error_messages', object: f.object
= f.text_field :trip_name, label: "What would you like to call this trip?"
= f.select :location, options_for_select(Vendor.allowed_locations, params[:location]), label: "Where will you be going?"
= f.date_select :start_date, { :label => "What is the start date for your trip?", :start_year => Time.new.year }
= f.number_field :number_of_days, value: 1, in: 1...90, label: "How many days will you be going for?"
.center= f.submit "Create Trip", class: "btn btn-large btn-primary"
干杯!
【问题讨论】:
-
您的代码实际上并没有显示您调用部分。你能显示你正在使用的导致错误的实际代码吗?
-
@matt,按要求完成!
标签: ruby-on-rails ruby haml partial nested