我正在Rails4中构建一个表单。当我添加div来为这个表单设置样式时,f.submit按钮停止工作。我没有更改控制器或模型。代码如下。谢谢!
计划视图中的 <div class="sidebar-widget">
<div class="Pricing-box">
<div class="price-title spacing-box">
<h4>Create a New Plan</h4>
</div>
<hr>
<div class = "sidebar-form"
<%= form_for(plan) do |f| %>
<div class="name-field">
<%= f.label :name %>
<%= f.text_field :name %>
</div>
<div class="time-field">
<%= f.label :time %>
<%= f.time_field :time %>
</div>
<div class="date-field">
<%= f.label :date %>
<%= f.date_select :date %>
</div>
<div class="restaurant-field">
<%= f.label :restaurant %>
<%= f.collection_select :restaurant_id, Restaurant.all, :id, :name %>
</div>
</div>
<div class="spacing-grid">
<%= f.submit "Create Plan", class: 'btn btn-md btn-black'%>
<% end %>
</div>
</div>
class PlansController < ApplicationController
def new
@plan = Plan.new
end
def create
@plan = Plan.create(plan_params)
@plan.users << current_user
redirect_to @plan
end
def index
@plans = Plan.all
#binding.pry
respond_to do |format|
format.html
format.js {}
end
end
<section class="ptb ptb-sm-50">
<div class="container">
<div class="row">
<div class="col-md-3 col-sm-4 mt-xs-30">
<%= render "plans/form", {plan: Plan.new } %>
<%= render "plans/all_plans", {plans: @plans} %>
</div>
</div>
</div>
</section>
答案 0 :(得分:0)
尝试修改form_for标记,使其如下所示:
<%= form_for @plan, url: {action: "create"} do |f| %>
这是Rails指南推荐的语法 - 不确定这是否能解决您的问题。