Paul
Paul

Reputation: 94

How can I use ruby on rails within my css using a style tag?

I have a blog using ruby on rails and when I create a post using active admin. I made it give me the choice of selecting a color. How can I use my post.color within my style tag of the background-color of my header in show.html.erb?

Like to github repo: https://github.com/pauldesign/blog_0.2

Upvotes: 0

Views: 493

Answers (2)

Gurmukh Singh
Gurmukh Singh

Reputation: 2017

You can do something like this:

<div style="color:<%= @post.color %>"></div>

Lokking at your question in the answer above. In your Post controller, show action, make sure you have something like this:

@post = Post.find(params[:id])

Now in your Project/show.html.erb you can access the value like so:

<div style="color:<%= @post.color %>"></div>

Upvotes: 1

Eduardo Veras
Eduardo Veras

Reputation: 981

if your "post.color" contains a color code or a valid html color name, then you should only need to do something like

<div style="color:<%= @post.color %>"></div>

ofcourse, you have to send that from your controller

Upvotes: 1

Related Questions