[英]How to use modal to create a new object in rails?
This is the current situation, a general rails app with index.html.erb
related to index
action, and a new.html.erb
with new
action to create a new object. 这是当前情况,具有与
index
操作相关的index.html.erb
的常规Rails应用程序,以及具有创建新对象的new
操作的new.html.erb
。
My request is that I want to use modal to replace the index.html.erb to create a new object. 我的要求是,我想使用模式替换掉index.html.erb来创建一个新对象。 In detail, when user click a
New
Button in the index.html
page, a dialog display with a form of creating object, instead of opening the new.html page. 详细地,当用户单击
index.html
页面中的“ New
按钮”时,将显示一个对话框,其中包含创建对象的形式,而不是打开new.html页面。
Is there a possible way to realise this ignoring copying the code in new.html.erb
to index.html.erb
? 有没有一种可能的方法来实现这一点,而
new.html.erb
将new.html.erb
的代码复制到index.html.erb
? Because it would also move the code in new action to index action. 因为它还会将新操作中的代码移动到索引操作。
I have tried an approach below, but it didn't meet my requirement: 我在下面尝试了一种方法,但是不符合我的要求:
<%= link_to "New sites", new_site_path, :class => "btn btn-primary", "data-toggle" => "modal", "data-target" => ".bs-example-modal-lg" %>
It would open a modal dialog including the components in application.html.erb
, such as navigation bar ,side bar and so on, not only the creating form. 这将打开一个模式对话框,其中包括
application.html.erb
的组件,例如导航栏,侧栏等等,而不仅仅是创建表单。
您可以在操作中设置“布局错误”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.