0

There are several pages generated from a same layout.rhtml. Besides a global css file, each page also has its own css file, say page1.css, page2.css corresponding to page1.rhtml, page2.rhtml. Is there any way to seletively load the css files in rhtml?

Thanks in advance.

2
  • I think you want to use .html.erb files. rhtml is really old and I dont think it is supported in Rails 3 and 4 (I can be wrong with this) Commented May 12, 2014 at 8:29
  • Do you want to load page1.css dynamically when page1 and page2.css when page2 actions are called? Commented May 12, 2014 at 8:54

2 Answers 2

2

Define a instance variable in controller for which css to load. lets say we will use stylefile variable in controller like this:

@stylefile = "page1.css"

Now write following code where you load css file.

<%= stylesheet_link_tag @stylefile %>

Similarly change filename in controller for page2.

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

Comments

2

If i understood correctly,you can just include them with stylesheet_link_tag like this

<%= stylesheet_link_tag 'page1' %>

<%= stylesheet_link_tag 'page2' %>

in the .rhtml files.

Comments

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.