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 4025930
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:54:28+00:00 2026-05-20T10:54:28+00:00

My goal is to generate a directory of static html, javascript, and image files

  • 0

My goal is to generate a directory of static html, javascript, and image files within my Rails (3) app, driven by ERB templates. For example, as a developer I might want to generate/update these files:

#{Rails.root}/public/products/baseball.html
#{Rails.root}/public/products/football.js

..from the following template files:

#{Rails.root}/product_templates/baseball.html.erb
#{Rails.root}/product_templates/football.js.erb

Ideally the templates would have access to my app’s Rails environment (including URL helpers, view helpers, partials, etc.).

What’s the latest and greatest way to accomplish this?

I experimented with a custom Rails generator, but found that I needed to write custom logic for skipping non-ERB files, substituting file names, etc. There must be a better way.

  • 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-20T10:54:28+00:00Added an answer on May 20, 2026 at 10:54 am

    This is how I accomplished something similar. It accepts source and destination directories, wipes out the destination, then processes the source directory, either ERB-processing files and placing them in the destination or simply copying them (in the case of on-ERB files). It would need to be modified to handle recursively processing a directory.

    I invoke it from a rake task like so:

    DirectoryGenerator.new.generate(Rails.root.join('src'), Rails.root.join('public', 'dest'))
    
    
    class DirectoryGenerator
      include Rails.application.routes.url_helpers
      include ActionView::Helpers::TagHelper
      default_url_options[:host] = 'www.example.com'
    
      def generate(source, destination)
        FileUtils.rmtree(destination)
        FileUtils.mkdir_p(destination)
    
        Dir.glob(File.join(source, '*')).each do |path|
          pathname = Pathname.new(path)
          if pathname.extname == '.erb'
            File.open(destination.join(pathname.basename.sub(/\.erb$/, '')), 'w') do |file|
              file.puts(ERB.new(File.read(path)).result(binding))
            end
          else
            FileUtils.cp(pathname, File.join(destination, pathname.basename))
          end
        end
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Example: </plugin> <plugin> <groupId>org.jvnet.jaxb2.maven2</groupId> <artifactId>maven-jaxb2-plugin</artifactId> <version>0.7.1</version> <executions> <execution> <goals> <goal>generate</goal> </goals> </execution> </executions> <configuration>
My goal is to generate a html file with tables and export them into
The goal is to generate an NSString chars in length and assign each string
Goal : I wants when I drag image it become fade so we can
I have a directory tree in which there are some files and some subdirectories.
The goal of my program is to grab a webpage and then generate a
I want a project directory like this: app/ | src/ Makefile All of the
I have a Makefile with the following type of rule: %.html: ./generate-images.py > $@
My main goal is to generate an XML file that can be downloaded. The
Goal Pass images generated by one process efficiently and at very high speed to

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.