执行摘要
亲爱的朋友们,
所以我在这个问题上花了两天时间。我有一个Bootstrap模式,我想用它来允许新的提交。我希望这可以通过ajax完成,并且从所有文档中,form_for()对象应该传递给:remote =>真。
我可以让我的表单在没有启用远程true的情况下工作,但当我将它放在我的form_for中时,它不再有效,我收到如下所列的语法错误。
请帮忙。
在布局中的applicaton.html.erb
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
的application.js
//= require jquery
//= require bootstrap-sprockets
//= require jquery_ujs
//= require turbolinks
//= require masonry/jquery.masonry
//= require masonry/jquery.infinitescroll.min
//= require_tree .
这是生成模态的HTML文件
<div id="largeModal" class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Submission</h4>
</div>
<div class="modal-body">
<%= render 'formnew' %>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
这是我的formnew.html.erb(这就是问题所在)
<%= form_for (@item, remote: true) do |f| %>
<% if @item.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@item.errors.count, "error") %> prohibited this item from being saved:</h2>
<ul>
<% @item.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="form-group">
<%= f.label :title %><br>
<%= f.text_area :title, {:class=> "form-control", :size => "30x10"} %>
</div>
<div class="form-group">
<%= f.label :subject %><br>
<%= f.text_area :subject, {:class=> "form-control", :size => "30x10"} %>
</div>
<div class="form-group">
<table class= "table-bordered">
<tbody>
<tr>
</tr>
</tbody>
</table>
</div>
<div class=" form-actions">
<%= f.submit %>
</div>
<% end %>
错误,我接受到我无法弄清楚(顺便说一下,没有REMOTE命令就能正常工作)
/home/vic/projects/projects/app/views/projects/_formnew.html.erb:2: syntax error, unexpected ',', expecting ')' ...fer.append= form_for (@item, remote: true) do |f| @output... ... ^
这是我的控制器
def index
@item = Item.new
page = params[:page]
if(page.blank? == false)
next_page =(page.to_i)
else
page = 0;
next_page = page+1
end
@objects = Object.paginate(page: next_page, per_page: 20).order("created_at DESC")
@next_link = next_page +1
respond_to do |format|
format.json { render :show, status: :created, location: @item }
format.html {render :index}
format.js {}
end
end
答案 0 :(得分:2)
好朋友:
<%= form_for (@item, remote: true) do |f| %> is INCORRECT
<%= form_for @secret, remote: true do |f| %> is CORRECT
这是我生命中不会再回来的6个小时。