Colloring HTML elements depending on what action is called

16 views
Skip to first unread message

Damián M. González

unread,
Jun 15, 2014, 9:41:29 PM6/15/14
to rubyonra...@googlegroups.com
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, 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.

--
Posted via http://www.ruby-forum.com/.

Hassan Schroeder

unread,
Jun 15, 2014, 10:23:00 PM6/15/14
to rubyonrails-talk
On Sun, Jun 15, 2014 at 6:40 PM, Damián M. González
<li...@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.s...@gmail.com
http://about.me/hassanschroeder
twitter: @hassan

Damián M. González

unread,
Jun 15, 2014, 10:36:03 PM6/15/14
to rubyonra...@googlegroups.com
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.
Reply all
Reply to author
Forward
0 new messages