开发者

What is wrong with this rails template?

开发者 https://www.devze.com 2023-02-18 04:28 出处:网络
I am attempting to take a whack at creating my first Rails application template and I am running into a slight issue with the copy_file method.

I am attempting to take a whack at creating my first Rails application template and I am running into a slight issue with the copy_file method.

First some background.... Apparently the Ruby OpenSSL package does not ship with a CA store, so any attempt to connect to an HTTPS service will fail out of the box. The way around this(for Rails 3 apps) is to add the line OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE to the top of your config/environment.rb file. I need to do this on the fly in my template so I can install jQuery.

So I have that all figured out, my general thought is to:

  1. Make a backup of my config/environment.rb file.
  2. Prepend the data to original
  3. Run the jquery:install --ui task
  4. Restore the original config/environment.rb file.

See my template Gist, Lines 25..34 is the relevant section.

So all of that works until step #4 which fails with Error: Could not find "env.orig" in any of your source paths on line #31.

This is VERY perplexing to me because line #28 works, I can see the env.orig file on disk, so why won't the reverse work?

What am I doing wrong?

Update 1:

After looking at the Thor source thor\actions.rb it became clear that Thor uses different paths (not your current project path) for the source and destination. Furthermore my copy was actually not working, it was actually coping the ERB template file, not the already generated file.

After a breather it occurred to me use the right tool for the job so now I have: run 'cp environment.rb environment.~' and run 'mv environment.~ environment.rb' which works just fine. I am fairly c开发者_如何学运维ertain this would not work on a windows box without the unix tools installed, but I can live with that. Does anyone have a better way?


See my Update for a Why, but the solution was to use the right tool for the job so now I have: run 'cp environment.rb environment.~' and run 'mv environment.~ environment.rb' which works just fine. I am fairly certain this would not work on a windows box without the unix tools installed, but I can live with that.

0

精彩评论

暂无评论...
验证码 换一张
取 消