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

  • SEARCH
  • Home
  • 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 7689381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:09:11+00:00 2026-05-31T20:09:11+00:00

I have a HTML/CSS File laid out with a bunch of areas that need

  • 0

I have a HTML/CSS File laid out with a bunch of areas that need adding. I have a ruby on rails application that would have a bunch of form elements that would then need to be added to this HTML/CSS file (it doesn’t need to be shown or anything, just edited and then saved). I don’t really understand how I can do this. I was looking at the file class, but got lost very quickly.

Any easy way to do this?

  • 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-31T20:09:12+00:00Added an answer on May 31, 2026 at 8:09 pm

    Writing to a file in Ruby is very simple:

    File.open(filename, 'w') do |f|
      f.write(content)
    end
    

    For an example in Rails try the following steps. Generate a new Rails app and a dummy scaffold by running:

    rails new erbfun
    cd erbfun
    rails g scaffold Stylesheet custom_css:text
    rake db:migrate
    mkdir -p public/system/stylesheets
    

    Then do something like this in your model:

    class Stylesheet < ActiveRecord::Base
      require 'erb'
    
      FOLDER = File.join(Rails.public_path,'system/stylesheets')
      TEMPLATE = <<-CSS
        body {
          font-family: Helvetica;
        }
        <%= custom_css %>
        /* some css comment here ... */
      CSS
    
      def save_to_file
        template = ERB.new(TEMPLATE)
        document = template.result(binding)
        filename = File.join(FOLDER,"stylesheet-#{Time.now.to_i}.css")
        File.open(filename, 'w') do |f|
          f.write(document)
        end
      end
    end
    

    and then try it out:

    $ rails c
    Loading development environment (Rails 3.2.2)
    1.9.3p125 :001 > s = Stylesheet.new custom_css: 'foobar'
     => #<Stylesheet id: nil, custom_css: "foobar", created_at: nil, updated_at: nil> 
    1.9.3p125 :002 > s.save!
     ...
     => true 
    1.9.3p125 :003 > s.save_to_file
     => 94 
    1.9.3p125 :004 > exit
    
    $ cat public/system/stylesheets/stylesheet-1332633386.css
        body {
          font-family: Helvetica;
        }
        foobar
        /* some css comment here ... */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume that I have some HTML page, and a corresponding CSS file. I'd like
So I have a page of HTML that has its own CSS file. It
I have a template in joomla without index.php I only have index.html, css file,
I have HTML + CSS text. I need some lib with simple function like
I have a html + css + javascript application. I want to be able
I have the following html/css that is causing problems in Firefox 1.5 and 2,
I've so far made a html and css file which have three images; title,
How do you setup a config.ru file to have Pow serve html/css/js files outside
I have a .html file containing text content like: <div> The study concludes that
I have an HTML page that I wrote that I need to host in

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.