"I have had success inserting straight HTML into my views by doing something like this:
def insert_some_html html = '<html tags>stuff</html tags>' return html end "
I think you wanted to say "inserting straight HTML into my helpers".
In case you really meant views, they should look like:
/views/test/test.rhtml (or test.erb.html if you are using Rails 2.x)
<h3>This is a test!</h3> <p>Pure HTML code should be inserted here</p> <p>If you want to use Ruby code use <%= 'this' %> form.</p> <% for client in @customers do %> <%= h client.name %> <% end %> <p>Notice that '<% %>' is the container for Ruby code. '<%=' returns the code inside the container. '<%' does not return code, used for blocks.</p>
To insert HTML in your helpers you can use something like
module MyHelper def show_last_5_posts "<p>This will return all this code</p>" end end
Then in the view you would use:
<p>Last five posts:</p> <%= show_last_5_posts %>
I don't like this approach. It inserts HTML code inside Ruby code, which is ugly. I use helpers to format links, strings, etc, like, for example, link_to_if_authorized.
If you have this "static" HTML code that shows the last 5 posts, you can create a partial. A partial is just like a view, it is named _partial.rhtml (for example _test.rhtml for a test partial) and you can render it trough <%= render :partial => 'test' %>.
So, a good approach for you would be to have a partial named recent_posts (file name _recent_posts.rhtml):
<p>Last five posts:</p> <% for post in posts %> <%= h post.title %><br /> <%= h post.text %><br /> <% end %>
In the view (ie home.rhtml) you would have <p>Hi all!</p> <%= render :partial => 'recent_posts', :locals => { :posts => @posts } %>
The :locals => { :posts => @posts } thingy in the render call above tells that the local variable 'posts' in the partial receives the @posts variable (which should exist in the view).
You should read this article: http://www.railsdev.ws/blog/wp-content/uploads/2007/10/modular_page_assembly_in_rails.pdf
Will help you a lot. Sure did help me!