• <legend id='zBsf8'><style id='zBsf8'><dir id='zBsf8'><q id='zBsf8'></q></dir></style></legend>

    <i id='zBsf8'><tr id='zBsf8'><dt id='zBsf8'><q id='zBsf8'><span id='zBsf8'><b id='zBsf8'><form id='zBsf8'><ins id='zBsf8'></ins><ul id='zBsf8'></ul><sub id='zBsf8'></sub></form><legend id='zBsf8'></legend><bdo id='zBsf8'><pre id='zBsf8'><center id='zBsf8'></center></pre></bdo></b><th id='zBsf8'></th></span></q></dt></tr></i><div id='zBsf8'><tfoot id='zBsf8'></tfoot><dl id='zBsf8'><fieldset id='zBsf8'></fieldset></dl></div>

        <small id='zBsf8'></small><noframes id='zBsf8'>

      1. <tfoot id='zBsf8'></tfoot>

          <bdo id='zBsf8'></bdo><ul id='zBsf8'></ul>

        Rails 部分模态(从不同模型渲染部分)

        Rails partial in modal (render partial from different model)(Rails 部分模态(从不同模型渲染部分))

        1. <tfoot id='w1m3d'></tfoot>

          <small id='w1m3d'></small><noframes id='w1m3d'>

            <tbody id='w1m3d'></tbody>

            <bdo id='w1m3d'></bdo><ul id='w1m3d'></ul>

              <legend id='w1m3d'><style id='w1m3d'><dir id='w1m3d'><q id='w1m3d'></q></dir></style></legend>

            1. <i id='w1m3d'><tr id='w1m3d'><dt id='w1m3d'><q id='w1m3d'><span id='w1m3d'><b id='w1m3d'><form id='w1m3d'><ins id='w1m3d'></ins><ul id='w1m3d'></ul><sub id='w1m3d'></sub></form><legend id='w1m3d'></legend><bdo id='w1m3d'><pre id='w1m3d'><center id='w1m3d'></center></pre></bdo></b><th id='w1m3d'></th></span></q></dt></tr></i><div id='w1m3d'><tfoot id='w1m3d'></tfoot><dl id='w1m3d'><fieldset id='w1m3d'></fieldset></dl></div>

                • 本文介绍了Rails 部分模态(从不同模型渲染部分)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我尝试将部分包含在类似于此 Rails 的模式中管理员当您点击创建语言"时.

                  I have tried to include a partial into a modal something similar to this Rails Admin when you click on "create language".

                  现在我还没有真正了解代码是如何在那里工作的,我尝试在这之间进行混合 Rails - AJAX 一个模态对话框? 和自己的东西.

                  Now as I have not really found out how the code works there, I tried to do a mix between this Rails - AJAX a Modal Dialog? and something own.

                  问题是,部分现在被渲染到模态中.但是当我点击保存"时,验证将返回到正常"的新建视图,并且不会直接在模式中显示验证错误.

                  The thing is, the partial gets rendered now into the modal. But when I hit "save", the validation will go back to the "normal" create-new view and not show the validation errors directly within the modal.

                  1. 如何在弹出的modal中直接显示验证错误?

                  1. How can I show the validation errors in the popped up modal directly?

                  当我保存时,我应该以某种方式区分来自此模式的保存和正常保存,因为此部分将从其他地方调用,并且需要将新创建的对象直接设置为 a 中的新对象落下.我想我需要区分响应格式,然后使用 JS 将新 id 设置为 DropDown id?

                  When I save, I should somehow distinguish between a save from this modal and a normal save, as this partial will be called from somewhere else and would need to set the new created object directly as a new Object within a drop down. I guess i would need to distinguish from a response format and then use JS to set the new id to the DropDown id?

                  这里有一些到目前为止写的代码.在我包含部分的视图中,它看起来像这样,我调用另一个控制器(因为我在不同的控制器新视图上).

                  Here some code written so far. In the view where I include the partial it looks like this where i call another controller (as I am on a different controllers-new-view).

                   $.get('<%= url_for :controller => 'customers', :action => 'new' %>',
                              function(data) {
                                  $('#customer-modal').html(data);
                              }
                      );
                  

                  然后customres"控制器中的new区分不同的请求格式并呈现不同的部分(在本例中为_ajax_form.html.erb"):

                  Then the new in the "customres" controller distinguishs between the different request format and renders the different partial (in this case "_ajax_form.html.erb"):

                  if request.xhr?
                    render "_ajax_form", :layout => false
                  

                  在这部分中,我使用simple_form_for @customer, :remote => true do |f]....",所以我猜最后提交看起来应该与标准不同,因为这称为正常的创建" 在控制器上?

                  In this partial, I use "simple_form_for @customer, :remote => true do |f]....", so I guess at the end the submit should look different than standard, as this calls the normal "create" on the controller?

                  <div class="modal-footer">
                      <%= f.button :submit, :class => 'btn primary' %>
                      <a id='cancel-form' class= "btn small info">cancel</a>
                    </div>
                  

                  感谢任何帮助澄清我做错了什么或应该如何做,因为我在 Rails 和 JS/AXAX 方面的经验还不是太有经验.. ;)

                  Thanks for any help which clarifies what I am doing wrong or how it should be done as my experience in Rails and JS/AXAX are not yet too experienced.. ;)

                  • 已我现在有一个版本,在我的特殊部分中加载到模式中,将在 simple_form_for 中调用名为new_from_sale"的单独操作:

                  simple_form_for @customer, :url =>url_for(:action => 'new_from_sale', :controller => 'customers') 做 |f|

                  然后在控制器中,当这个新对象的保存正常时,我重定向到第一个调用的视图,并将新的 id 作为参数,然后填充下拉列表.在其他情况下,当无法保存新对象时,我需要以某种方式显示仍在该模式中的错误.到目前为止,两者都尝试直接渲染部分 render :partial =>"customers/ajax_form" 或回馈 JS 代码 render :js =>"$('#sale_customer_id').val(#{@customer.id});" 还不行.. 但我会继续试试我的运气..

                  Then in the controller, when the save is ok of this new object, I redirect to the first called view with the new id as a param which then fills the dropdown. In the else case, when the new object can not be saved, I need somehow to show the errors still in that modal. So far both tries to either directly render the partial render :partial => "customers/ajax_form" or give back JS code render :js => "$('#sale_customer_id').val(#{@customer.id});" would not yet work.. but I'll keep on trying my luck..

                  推荐答案

                  这是一个基本示例,说明我将如何做一个模态表单,我写了一个类似的问题 (Rails 和模态 jquery 对话框表单):

                  Here's a basic example of how I'd do a modal form which I wrote in response to a similar question (Rails and modal jquery dialog form):

                  https://github.com/ramblex/modal-form

                  你需要添加 :remote =>true 到加载到对话框中的表单.这将导致从创建操作呈现 JS 格式.然后,您可以在 create.js.erb 中处理响应.

                  You need to add :remote => true to the form that gets loaded into the dialog. That will cause the JS format to be rendered from the create action. You can then handle the response in a create.js.erb.

                  这篇关于Rails 部分模态(从不同模型渲染部分)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Draw border around nontransparent part of image on canvas(在画布上的图像不透明部分周围绘制边框)
                  dragging and resizing an image on html5 canvas(在 html5 画布上拖动图像并调整其大小)
                  What#39;s the difference between a boolean as primitive and a boolean as property of an object?(作为原始对象的布尔值和作为对象属性的布尔值有什么区别?)
                  I want to do animation of an object along a particular path(我想沿特定路径对对象进行动画处理)
                  How to upload image into HTML5 canvas(如何将图像上传到 HTML5 画布中)
                  How to show a running progress bar while page is loading(如何在页面加载时显示正在运行的进度条)

                  <small id='JDNcr'></small><noframes id='JDNcr'>

                  • <tfoot id='JDNcr'></tfoot>
                    <i id='JDNcr'><tr id='JDNcr'><dt id='JDNcr'><q id='JDNcr'><span id='JDNcr'><b id='JDNcr'><form id='JDNcr'><ins id='JDNcr'></ins><ul id='JDNcr'></ul><sub id='JDNcr'></sub></form><legend id='JDNcr'></legend><bdo id='JDNcr'><pre id='JDNcr'><center id='JDNcr'></center></pre></bdo></b><th id='JDNcr'></th></span></q></dt></tr></i><div id='JDNcr'><tfoot id='JDNcr'></tfoot><dl id='JDNcr'><fieldset id='JDNcr'></fieldset></dl></div>
                    • <bdo id='JDNcr'></bdo><ul id='JDNcr'></ul>
                        <tbody id='JDNcr'></tbody>

                          1. <legend id='JDNcr'><style id='JDNcr'><dir id='JDNcr'><q id='JDNcr'></q></dir></style></legend>