I have a pretty basic blog app on rails, and I need help creating a method.
For each post, the user has to specify a neighborhood, and for styling purposes, I want to find out if that neighborhood falls in a certain bucket so I can color that post accordingly. For instance, the neighborhood "SOMA" is a part of the bucket "Downtown."
I imagined that what I would do is pass the neighborhood into a method that determines which bucket it falls in and I can somehow output the bucket to correspond to a div class in the index. Open to other suggestions.
Does anyone know where a method like this would live?
Update:
I added a barebones method in PostsHelper to even see if it works, then i can flesh out the logic
module PostsHelper
def bucket(neighbor)
case neighbor
when "SOMA"
puts "Downtown"
when "Mission"
puts "Dolores"
else
puts "foo"
end
end
end
Then I tried calling the method in the post index and nothing happens. This may be the dumbest question ever, but what am I missing? Is this even the right way to go about it?:
<ul id="post-list">
<% @posts.each do |post| %>
<li><%= post.content %></li>
<li><%= post.attribution %> in <%= post.neighborhood %>
<span class="post-date"><%=time_ago_in_words(post.created_at) %> ago</span></li>
<li> <%= bucket(yield(post.neighborhood)) %> </li>
<% end %>
</ul>