I have some ruby code in a view and it works great but I know that's not the correct way to do it so want to put it into a helper method (thanks @SimoneCarletti). I'm having some difficulty with that and usually I find people on here 10000x smarter than me who are excellent Rubyists.
Here is the code that I want to put into a helper
product_feed_item.voters_who_voted.map(&:full_name).join(("<br />").html_safe)
Here is the method below in my user model to get the user's product_feed
def product_feed
Design.from_users_followed_by(self).to_a.concat Product.from_users_followed_by(self).to_a
end
The controller for this view is
@product_feed_items = current_user.product_feed
@product_feed_items.sort! {|t1, t2| t2.created_at <=> t1.created_at}
respond_to do |format|
@product_feed_items = @product_feed_items.paginate(:page => params[:page], :per_page => 20)
format.html
format.json { render json: @product_feed_items }
end
and the View is
<%= render partial: "shared/product_feed_item", collection: @product_feed_items %>
Where the partial contains the first block of code I want to extract into a method.
How can I put this into a method?? If you need me to clarify or add anything to help please just let me know.
Thanks in advance for helping! Happy Holidays!