Using helpers in rails 3 to output html?

I agree with the comment above recommending the use of a partial... but if you DID need to do this in a helper, this is a cleaner way to implement: def display_all(collection) content_tag(:ul, :class => "list") do collection. Collect do |member| content_tag(:li, :id => member.name. Gsub(' ', '-').downcase.

Strip) do member. Name end end end end I'd pass in a collection explicitly rather than passing in a symbol to create a collection so you aren't always required to display ALL the records in a particular table at once. You could add pagination, etc.

Yeah I agree that if I were to do it this way, this is the best way to do it. But as the other guys said, I"m going to use a partial instead. Thanks!

– TheDelChop Sep 5 '10 at 17:28.

Joe, You can still use your method display_all(collection_sym) Just use: return html. Html_safe instead of: return html I still find that in many situations, it is better to generate HTML from helpers, instead of using partials. So the html_safe function in Rails 3 will make sure that you generate HTML, instead of converting it to String.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions