Forum: Ruby on Rails Coloring HTML elements depending on what action is called

5b972395a92333843018b4add8af0437?d=identicon&s=25 Damián M. González (igorjorobus)
on 2014-06-16 03:40
Hi fellows. I'm requiring a suggestion, a hand, since can't solve this.
What I'm trying to do is this:

 I have 2 actions by a controller. There's an active layout for
both(application.html.erb). There's two HTML elements defined in the
layout which I want to be collored diferently if one action is called or
the another. I suspect that can be done with Javascript, but must be an
easy way. What I though is that when I call one of the actions, it must
render a specific CSS file, which overwrite the style of the HTML
elements(defined by default in application.css), giving to them the
color I want, but....I can't give with it, can't get it work correctly.
Can you give me a clue about what should I do, I've been around this a
whole day.
Bee69cfed999cd13e3bff73d472a39ee?d=identicon&s=25 Hassan Schroeder (Guest)
on 2014-06-16 04:23
(Received via mailing list)
On Sun, Jun 15, 2014 at 6:40 PM, Damián M. González
<lists@ruby-forum.com> wrote:

>  I have 2 actions by a controller. There's an active layout for
> both(application.html.erb). There's two HTML elements defined in the
> layout which I want to be collored diferently if one action is called or
> the another.

Why not just define CSS classes for the two styles in a common
style sheet and set an instance variable in the controller to pass to
the view? e.g.

  <div class="<%= @actionclass %>"> ... </div>

I can imagine other approaches, but that seems simplest.

FWIW,
--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
http://about.me/hassanschroeder
twitter: @hassan
5b972395a92333843018b4add8af0437?d=identicon&s=25 Damián M. González (igorjorobus)
on 2014-06-16 04:35
Yes Hassan that's a big better solution than the JS one, you opened my
mind, I appreciate it, thanks. Still I'm open to receive other
suggestions of ways to do this, for the sake of learn.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.