A
A
Alexander2014-05-30 15:13:54
Ruby on Rails
Alexander, 2014-05-30 15:13:54

Choosing partial, what's wrong with creating a post?

The task was to make 2 types of posts: important, less important. Accordingly, they must have different layouts and partials. I started to implement it like this:
In new.html.erb
We get true or false

<%= f.collection_radio_buttons :priority, , :first, :last %>

In index.html.erb
If true - mini_post
If false - post
<% for post in @posts %>
  <% if post.priority == true %>
    <%= render partial: 'mini_post' %
  <% else %>
    <%= render post %>
  <% end %>
<% end %>

Outputs only _post.html.erb, but _mini_post.html.erb does not want to display, although the priority is set successfully in the terminal. What could I be wrong about?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimitriy, 2014-05-31
@Vakiliy

Try like this, in the model:

def to_partial_path
  priority? ? 'mini_post' : super
end

In the view
<%= render @posts %>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question