Rails Bootstrap Modal Remote True在form_for中不起作用

时间:2015-05-13 16:16:41

标签: ruby-on-rails twitter-bootstrap-3 bootstrap-modal

执行摘要

  1. 我在已创建的Rails 4服务器上安装了Bootstrap模式
  2. 此模态用于通过远程提交新帖子:true
  3. 我在表单提交过程中收到错误消息称远程无法正常工作。
  4. 表单实际上可以提交成功但没有远程true,但它不是ajax。
  5. 我的遥控器有什么问题:真正的线路。它是直接切割和粘贴。
  6. 亲爱的朋友们,

    所以我在这个问题上花了两天时间。我有一个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">&times;</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
    

1 个答案:

答案 0 :(得分:2)

好朋友:

<%= form_for (@item, remote: true) do |f| %> is INCORRECT
<%= form_for @secret, remote: true do |f| %> is CORRECT

这是我生命中不会再回来的6个小时。