我确信我在这里只是遗漏了一些简单的东西,但是我不能为我的生活弄明白什么。
我有一个表单,用于更新模型的属性。
<%= form_for @gf do |f| %>
<div class="form-field">
<%= f.text_field :first_name, :placeholder => "First Name" %>
</div>
<div class="form-field">
<%= f.text_field :last_name, :placeholder => "Last Name" %>
</div>
<div class="form-field">
<%= f.text_field :address_line_one, :placeholder => "Address" %>
</div>
<div class="form-field">
<%= f.text_field :address_line_two, :placeholder => "Address (second line)" %>
</div>
<div class="form-field">
<%= f.text_field :city, :placeholder => "City" %>
</div>
<div class="form-field">
<%= f.text_field :state, :placeholder => "State" %>
</div>
<div class="form-field">
<%= f.text_field :zip_code, :placeholder => "Zip Code" %>
</div>
<div class="form-field">
<%= f.text_field :phone_number, :placeholder => "Phone Number" %>
</div>
<div class="form-field">
<%= f.submit "Submit" %>
</div>
<%end%>
相关的控制器是
def home
if current_user.girlfriends.all.count == 0
@gf = Girlfriend.new
@gf.user_id = current_user.id
else
@gf = current_user.girlfriends.first
end
end
def new
raise
end
def create
raise
end
def update
raise
end
def delete
raise
end
在我的routes
文件中
resources :girlfriends
表单位于/home
页面上,因此正确设置了@gf
变量。表单使用适当的属性填充适当的字段。但是 - 当我点击Submit
时没有任何反应。没有更改URL,页面上没有任何操作,我没有在任何CRUD操作中点击raise
....我错过了什么?提前感谢您的帮助。
编辑:这是实际呈现的HTML。
<form accept-charset="UTF-8" action="/girlfriends/1" class="edit_girlfriend" id="edit_girlfriend_1" method="post"><div style="display:none"><input name="utf8" type="hidden" value="✓" /><input name="_method" type="hidden" value="patch" /><input name="authenticity_token" type="hidden" value="CIPzkLLWwmclyOwKpkphMJ5u8Saxhx6ajDq/NvW8Lfc=" /></div>
<div class="form-field">
<input id="girlfriend_first_name" name="girlfriend[first_name]" placeholder="First Name" type="text" value="Melissa" />
</div>
<div class="form-field">
<input id="girlfriend_last_name" name="girlfriend[last_name]" placeholder="Last Name" type="text" />
</div>
<div class="form-field">
<input id="girlfriend_address_line_one" name="girlfriend[address_line_one]" placeholder="Address" type="text" />
</div>
<div class="form-field">
<input id="girlfriend_address_line_two" name="girlfriend[address_line_two]" placeholder="Address (second line)" type="text" />
</div>
<div class="form-field">
<input id="girlfriend_city" name="girlfriend[city]" placeholder="City" type="text" />
</div>
<div class="form-field">
<input id="girlfriend_state" name="girlfriend[state]" placeholder="State" type="text" />
</div>
<div class="form-field">
<input id="girlfriend_zip_code" name="girlfriend[zip_code]" placeholder="Zip Code" type="text" />
</div>
<div class="form-field">
<input id="girlfriend_phone_number" name="girlfriend[phone_number]" placeholder="Phone Number" type="text" />
</div>
<div class="form-field">
<input name="commit" type="submit" value="Submit" />
</div>
答案 0 :(得分:5)
听起来您的页面上有JavaScript可以防止提交表单。
答案 1 :(得分:0)
正如你所说,网址没有变化。在您的视图中创建show.html.erb文件和
试试这个
<% form_for :girlfriend, @gf, :url=> {:action => :create},:html => { :method => :post }do |f| %>
并为您的表单内容制作new.html.erb;并修改您的控制器
def new
@gf = Girlfriend.new
end
答案 2 :(得分:0)
当您在页面上调用两次jQuery时,会发生此JS事件。示例:gemfile中有调用,assets / javascripts中有另一个query.js文件