0

Hey people sorry it this seems stupid! I usually code in PHP so this is very different! In PHP I would write...

<?php include 'somefile.php'; ?>

Now in ruby I have my .rhtml which contain instances of <%= Something %> and <% something %> I have two RHTML files one.html and two.rhtml How to I render one within another? I'm not trying to render scripts just plain HTML inside a .rhtml file type.

I have tried <% include('two.rhtml');%> as in http://www.phptoruby.com/tag/include

could someone give my some guidance ?

Many many thanks in advance.

2 Answers 2

2

You should be using

render products/show

where show will be a partial.

Referring to http://guides.rubyonrails.org/layouts_and_rendering.html would help. Explanation:

In one.rhtml code will be as follwos:

here assumption is that one.rhtml and two.rhtml are in the same folder of views. If there are in different folder you will like to mention the path like <%= render products/show %> where _show.rhtml is being called from product's folder of views.

Remember that partial files are named as _show.rhtml, _.html.erb

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for this. Do i need to define elsewhere where the products view folders are? or is it just products in relation to where one.rhtml is?
2

You have to render a partial Rails Partials

You have to save the file that you want to call with an _(underscore) like _two.html.erb and then call that partial in one.html.erb with

render "two"

I usually create a folder for the partials, for example I create a folder called partials inside app/views and inside partials I create the partials I need, then call them with

render "partials/partial_name"

2 Comments

Odd, this is giving me errors. How do i diagnose errors in rhtml files?
Can you check changing the files to extension html.erb?, I think new version of rails doesn't support rhtml anymore

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.