【问题标题】:nested namespace on form_for helper method - Railsform_for 辅助方法上的嵌套命名空间 - Rails
【发布时间】:2016-01-21 18:27:08
【问题描述】:

大家好,我有两个命名空间,一个嵌套在另一个表单中

admin(命名空间)在 admin 我有博客(命名空间)

我知道我可以将如下的命名空间放入 form-for helper 中。

<%= 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 前缀呢?

【问题讨论】:

    标签: ruby-on-rails ruby namespaces


    【解决方案1】:

    找到了。

    供日后参考

    您只需根据命名空间的顺序添加一个逗号

    以上情况

    <%= 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>
    

    【讨论】:

      猜你喜欢
      • 2011-02-12
      • 2013-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-06
      • 1970-01-01
      相关资源
      最近更新 更多