How to share constants across various Rails assets

时间:2016-04-04 18:29:08

标签: ruby-on-rails model-view-controller sass

I have a variable $foo defined in my SCSS/SASS file. I want to be able to also access $foo (as a constant) in my model file, 'bar-model.rb'. How can I do this?

1 个答案:

答案 0 :(得分:0)

也许你可以:

  • 使用数据属性(例如<div data-images-per-row="<%= @images_per_row %>"></div>并通过Javascript
  • 访问它)

然而,这并没有感觉到&#34;对我来说。也许你正在寻找类似in_groups_of的东西?

<table>
<% @tasks.in_groups_of(4, false) do |row_tasks| %>
  <tr>
    <% for task in row_tasks %>
      <td><%= image_tag task.image %></td>
    <% end %>
  </tr>
<% end %>
</table>