Ondra
Ondra

Reputation: 3180

Rails multiple developers environments

In our company, people are using different operating systems. I am using Linux and have line in development.rb like:

Paperclip.options[:command_path] = "/usr/bin"

Designer, who is on Windows need different line. Is there any way, how to manage different developers in ruby on rails? Thanks a lot!

Upvotes: 1

Views: 752

Answers (2)

Unixmonkey
Unixmonkey

Reputation: 18784

If it's just a platform issue, try something like this:

if RUBY_PLATFORM =~ /mswin/
  Paperclip.options[:command_path] = 'c://ruby/bin'
else
  Paperclip.options[:command_path] = '/usr/bin'
end

A good way to keep machine-specific settings is with a configuration file. Treat the settings.yml like database.yml and copy the example to settings.yml on each user's machine.

# .gitignore
config/settings.yml

# config/settings.yml.example
paperclip_command_path: /usr/bin
some_api_key: put_key_here

# config/initializers/load_settings.rb
filename = File.join(File.dirname(__FILE__), '..', 'settings.yml')
if File.file?(filename)
  APP_CONFIG = YAML::load_file(filename)
  APP_CONFIG.each do |k, v|
    v.symbolize_keys! if v.respond_to?(:symbolize_keys!)
  end
end

This way you could set the above like this:

Paperclip.options[:command_path] = APP_CONFIG[:paperclip_command_path]

Upvotes: 2

Max Williams
Max Williams

Reputation: 32933

One solution: Create a folder in config called "personal", and put a file in it, the contents of which are set to be ignored in whatever source control system you use. Then within that, each developer can set their own options which override the above. To make sure that it doesn't matter which line gets evaluated first, you set it up like:

#in config/development.rb
Paperclip.options[:command_path] ||= "/usr/bin"

#in config/personal/overrides.rb
if RAILS_ENV == "development"
  Paperclip.options[:command_path] = "/my/local/path"
end

Now, if overrides runs first, the line in development.rb won't override it.

I do something similar in this in one of my projects to send out emails in dev mode using a gmail account i own instead of the usual email sending system.

Upvotes: 3

Related Questions