Rails Gem:如何获得gem应用程序布局?

时间:2016-06-02 15:02:49

标签: ruby-on-rails ruby-on-rails-4

我尝试使用默认的CRUD-Views自定义Rails Gem。

app / views / new.html.erb:

<div class="wishlist">
  <div class="row">
    <div class="small-12 medium-10 large-8 small-centered columns">

      <h1><%= Spree.t(:creating_wishlist) %></h1>
      <%= form_for @wishlist do |f| %>
      <p><%= f.label :name, Spree.t(:name) %>:&nbsp;<%= f.text_field :name %></p>
      <p><%= f.check_box :is_private %>&nbsp;<%= f.label :is_private, Spree.t(:is_private) %></p>
      <%= f.submit Spree.t(:create) %>
      <% end -%>

    </div>
  </div>
</div>

我想在所有其他视图中避免使用相同的div容器.wishlist .row等。 我怎样才能实现以下目标:

# gem application layout:
<div class="wishlist">
  <div class="row">
    <div class="small-12 medium-10 large-8 small-centered columns">

      <%= yield %>

    </div>
  </div>
</div>

当我将其保存为app / views / layouts / application.html.erb并在gem控制器中使用layout&#39; application&#39;然后将覆盖主Rails应用程序布局的视图。 但我只想要Gem CRUD视图来获得收益。

1 个答案:

答案 0 :(得分:0)

我可以使用我在CRUD视图的do / end-block之外渲染的部分来解决它:

app in app / views / base / _layout.html.erb

<div class="wishlist">
  <div class="row">
    <div class="hide-for-small medium-1 large-2 columns"></div>
    <div class="small-12 medium-10 large-8 small-centered columns">
      <%= yield %>
    </div>
    <div class="hide-for-small medium-1 large-2 columns"></div>
  </div>
</div>

在我的CRUD视图中:

<%= render :layout => 'base/layout' do %>
  # content
<% end -%>