Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails-在索引站点的模式中编辑失败_Ruby On Rails_Twitter Bootstrap - Fatal编程技术网

Ruby on rails Rails-在索引站点的模式中编辑失败

Ruby on rails Rails-在索引站点的模式中编辑失败,ruby-on-rails,twitter-bootstrap,Ruby On Rails,Twitter Bootstrap,我有一个组列表,我想通过modal编辑一个组名。我使用edit.js.erb文件和引导模式 有两种情况,都是错误的 第一: 在部分和链接中使用“remote:true”(在单行文件中) 然后显示模态,但在单击“保存”按钮后,始终会再次渲染,并且从不关闭。(我不知道为什么) 第二: 删除远程:从部分删除为true。 然后显示模态,我甚至可以保存更改。但当我键入错误的名称(空白或太长)时,控制器崩溃中的行“render‘edit’”。(错误:“缺少模板组/编辑,应用程序/编辑…”。我认为rails当

我有一个组列表,我想通过modal编辑一个组名。我使用edit.js.erb文件和引导模式

有两种情况,都是错误的

第一: 在部分和链接中使用“remote:true”(在单行文件中) 然后显示模态,但在单击“保存”按钮后,始终会再次渲染,并且从不关闭。(我不知道为什么)

第二: 删除远程:从部分删除为true。 然后显示模态,我甚至可以保存更改。但当我键入错误的名称(空白或太长)时,控制器崩溃中的行“render‘edit’”。(错误:“缺少模板组/编辑,应用程序/编辑…”。我认为rails当时不知道edit.js.erb,但如何修复它

你对这种情况有什么想法吗

控制器

def edit
 @group = current_user.groups.find_by(id: params[:id])
 respond_to do |format|
   format.js # actually means: if the client ask for js -> return file.js
 end
end

def update
 @group = current_user.groups.find_by(id: params[:id])
 if @group.update_attributes(group_params)
  flash[:success] = "Nazwa grupy została zmieniona"
  redirect_to groups_path
 else
   render 'edit'
 end
end
用于在模式中显示表单_的部分

<%= form_for(@group, remote: true) do |f| %>
<div>
    <%= render 'shared/error2_messages', object: f.object%>
    <p>
        <%= f.label :name, "Nazwa" %>
        <%= f.text_field :name, class: 'form-control'%>
    </p>
</div>
<%= f.submit yield(:button_name), class: "btn btn-primary" %>
<% end %>


edit.js.erb文件

<% provide(:button_name, 'Zapisz zmiany') %>
$('.modal-title').html("Edytuj nazwę grupy");
$('.modal-body').html("<%= escape_javascript( render partial: 'layouts/group_data_form', locals: {group: @group} ) %>");
$('#myModal').modal();

$('.modal title').html(“Edytuj nazwęgrupy”);
$('.modal body').html(“”);
$('#myModal').modal();
列表中的单行

<li id="group-<%= group.id %>" class="list-group-item">
<span class="group-name"><%= group.name %></span>

<%= link_to edit_group_path(group.id), remote: true, :class => "edit-option btn" do %>
    <i class="fa fa-pencil-square-o fa-2x" ></i>
<% end %>
<%= link_to group, method: :delete, data: { confirm: "Na pewno chcesz usunąć tę grupę?" }, :class => "delete-option btn btn-danger" do %>
    <i class="fa fa-trash-o" > usuń</i>
<% end %>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">Zmień nazwę grupy</h4>
            </div>
                <div class="modal-body">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
                </div>
        </div>
    </div>
</div>
  • “编辑选项btn”do%> “删除选项btn btn danger”do%> 乌苏 &时代; 兹米纳兹瓦格鲁比 阿努鲁伊

  • 这看起来像是你昨天问题的后续行动

    我不会说你的两种方法都是错误的,我会说你正以这种方式将两种正确的方法结合在一起

    (1) 由于您使用了
    js
    发送save(在表单上使用
    remote:true
    ),因此您只需在成功保存时关闭模式,即可从
    update.js.erb
    中定义save as(就像您在编辑中为
    format.js
    定义了
    edit.js.erb
    ),如下所示:

    #update.js.erb
    <% if @group.errors.empty? %>
      $('.modal-body').html("");
      $('#myModal').modal('hide');
      $("#notice").html("Group was successfully updated.");
    <% else %>
      $("#notice").html("Error! Group not updated.");
    <% end %>
    
    #controller update action
    def update
      @group = current_user.groups.find_by(id: params[:id])
      @group.update_attributes(group_params)
      respond_to do |format|
        format.html
        format.js
      end
    end
    

    但是请注意,这可能不会打开你的模式,它将转到你的应用程序的
    编辑组路径
    ,即
    /groups/:id/edit

    ,你对第一种情况的回答似乎是正确的。但是当我创建update.js.erb时,什么都没做。看起来rails不知道应该呈现它。我应该在控制中更改任何其他内容吗ler或其他什么地方?我甚至不知道如何正确调试它。将
    remote:true
    返回到表单:
    ,并在
    更新
    操作中指定
    格式.js
    ,就像上面添加到我的答案中一样。我做了这些事情。仍然没有做任何事情。当我单击“保存”时,模态仍然打开。似乎“”不适用于update.js.erb。请将
    $('#formModal')。modal('hide');
    更改为
    $('#myModal')。modal('hide');
    。目标
    id
    假定为您的modal的
    id
    。我也对我的回复帖子进行了更改。
    def edit
     @group = current_user.groups.find_by(id: params[:id])
     respond_to do |format|
       format.js # actually means: if the client ask for js -> return file.js
       format.html
     end
    end