Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6687923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:20:42+00:00 2026-05-26T05:20:42+00:00

I am certain I am just doing this the wrong way, but I cant

  • 0

I am certain I am just doing this the wrong way, but I cant get this to work with assets:precompile and im not sure it should be even.

#plant.css.erb
<%
plants = Plant.all
if plants
  plants.each do |plant|
%>
    .plant_<%= plant.id %> {
        background-color: #<%= plant.color %>;
        padding: 1px;
    }
<%
  end
end
%>

I get this error:

Invalid CSS after "...kground-color: ": expected expression (e.g. 1px, bold), was "#;"
/rails/ship/releases/20111006191503/app/assets/stylesheets/application.css)

I appreciate any help that anyone can give. If I did not provide enough info, let me know what I need and I will gladly provide it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:20:42+00:00Added an answer on May 26, 2026 at 5:20 am

    I’m not sure what’s wrong with your syntax, but the approach as a whole seems a bit upside down from the norm. Typically one would not create a new CSS rule for each object. Why not something like

    # views/plants/index.html.erb
    <div class="plant plant-<%= plant.color %>
    ...
    </div>
    

    and then in your CSS file (no need for ERB) define just a few classes

    # plant.css
    plant_red {background-color: #F00;}
    plant_blue {background-color: #00F;}
    

    Maybe you’re not doing that because there are not a finite number of different colored plants? E.g. you have a whole rainbow of colors? In that case, it’s really more appropriate to go “old school” and use the style tag:

    # views/plants/index.html.erb
    <div class="plant" style="background-color:#<%= plant.color %>" >  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not certain what I am doing wrong, but I have a class
Just trying to get diff to work better for certain kinds of documents. With
I often want to trigger a certain function just once, but I need to
I just finished looking at this question: https://stackoverflow.com/questions/753122/which-cloud-computing-platform-should-i-choose But, I am not certain what
I just worked with C# but do not have any idea on Silverlight so
My first question here, hopefully I'm not doing it wrong. My problem is that
Okay, I'm not doing anything fancy here, but it's driving me crazy that I
I think I've been doing this wrong for the past year and a half
I am creating a program that displays a popup at certain times (just like
I was just prototyping a new system for deferring certain operations until out of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.