大家好,我有两个 namespace ,一个嵌套在另一个表单中
admin (namespace) inside admin 我有 blog (namespace)
我知道我可以将下面的命名空间放在 form-for 帮助器中。
<%= form_for [:blog, @post] do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<div class="large-12 columns">
<div class="field panel">
<%= f.label :title %><br>
<%= f.text_field :title %>
</div>
<div class="field panel">
<%= f.label :body %><br>
<%= f.text_field :body %>
</div>
<div class="actions">
<%= f.submit %>
<%= link_to 'Back', admin_blog_posts_path %>
</div>
</div>
<% end %>
但是我怎样才能在它前面加上前缀 :admin namespace
呢?
最佳答案
找到了。
供以后引用
您只需根据命名空间的顺序添加一个逗号
在上面的例子中
<%= form_for [:admin,:blog, @post] do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<div class="large-12 columns">
<div class="field panel">
<%= f.label :title %><br>
<%= f.text_field :title %>
</div>
<div class="field panel">
<%= f.label :body %><br>
<%= f.text_field :body %>
</div>
<div class="actions">
<%= f.submit %>
<%= link_to 'Back', admin_blog_posts_path %>
</div>
</div>
关于ruby-on-rails - form_for 辅助方法上的嵌套命名空间 - Rails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33281651/