Syntax Error in application.yml File - ruby-on-rails

I am running the command rail s and it displays the following error:
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/settingslogic-2.0.9/lib/settingslogic.rb:189:in `missing_key': Missing setting 'mail_from' in /home/user/myapp/my_app/config/application.yml (Settingslogic::MissingSetting)
what is wrong in application.yml?
my config/application.yml
defaults: &defaults
site_name: site
host: site
url: site
resque:
server: 127.0.0.1:6379
namespace: resque_namespace
smtp:
domain: domain
login: login
password: secret
server: host
port: 25
mail_from: mail#example.com
robokassa:
login: login
test_mode: false
pass1: secret
pass2: secret
token: secret
avisosms:
login: login
service_id: 666
hash: secret
sdpays:
md5: secret
project_id: 666
edit_delay: 5
contest_id: 1
aws:
ses:
access_key_id: secret
secret_access_key: secret
s3:
access_key_id: secret
secret_access_key: secret
bucket: bucket
fog_directory: dir
s3cmd: /usr/bin/s3cmd
vk:
key: key
secret: secret
recaptcha:
public_key: key
private_key: private_key
development:
#<<: *defaults
host: 'localhost:3666'
url: 'http://localhost:3666'
resque:
server: '127.0.0.1:6379'
namespace: 'bdsmg_development_resque'
aws:
ses:
access_key_id: key
secret_access_key: secret
s3:
access_key_id: key
secret_access_key: secret
bucket: bucket
fog_directory: dir
s3cmd: /usr/local/bin/s3cmd
staging:
<<: *defaults
test_email: mail#example.com
host: host
url: http://host
test:
<<: *defaults
production:
<<: *defaults
Any help will be appreciated.

This seems to be some indentation issue. The mail_from field needs to be inside the smtp block.
smtp:
domain: domain
login: login
password: secret
server: host
port: 25
mail_from: mail#example.com

Related

FakeS3 and Paperclip (on Rails) is still defaulting to HTTPS in URLs

I'm using the configuration from this page: http://codesthq.com/blog/2015/gratuitious-development-with-aws-s3-and-paperclip.html
I can upload files to the local FakeS3 server, but when I generate a URL it returns a https:// link not https:// and I can't find a configuration option that changes it. I figure since the upload is working correctly, this is more likely a paperclip issue?
Here's my configuration:
config/initializers/aws.rb:
AWS::Rails.load_yaml_config
config/initializers/paperclip.rb:
paperclip_defaults = Rails.application.config_for :paperclip
paperclip_defaults.symbolize_keys!
Paperclip::Attachment.default_options.merge! paperclip_defaults
config/aws.yml:
development: &development
access_key_id: "abc"
secret_access_key: "abc"
s3_endpoint: "localhost"
s3_port: 10001
s3_force_path_style: true
use_ssl: false
test: *development
production: &production
access_key_id: <%= ENV["AWS_ACCESS_KEY_ID"] %>
secret_access_key: <%= ENV["AWS_SECRET_ACCESS_KEY"] %>
staging: *production
config/paperclip.yml:
development:
storage: :s3
bucket: "development"
s3_host_name: "localhost"
url: ":s3_alias_url"
s3_host_alias: "localhost:10001/development"
s3_protocol: 'http'
test:
storage: :s3
bucket: "test"
s3_host_name: "localhost"
url: ":s3_alias_url"
s3_host_alias: "localhost:10001/test"
s3_protocol: 'http'
production: &production
storage: :s3
bucket: <%= ENV["S3_BUCKET_NAME"] %>
url: ":s3_domain_url"
staging: *production
Versions installed:
$ bundle list | grep paperclip
* paperclip (4.3.6)
$ bundle list | grep aws
* aws-sdk (2.3.7)
* aws-sdk-core (2.3.7)
* aws-sdk-resources (2.3.7)
* aws-sdk-v1 (1.66.0)
Doh, I was over-riding s3_protocol in the model's attachment configuration!

How to use secret keys from secrets.yml in Travis ci?

I need two keys from S3 storage in my repo to make Travis tests pass.
I used travis gem to encrypt my keys:
travis encrypt "aws_access_key=MYSUPERSECRETKEY" --add env
travis encrypt "aws_secret_key=MYSUPERSECRETKEY" --add env
And got travis.yml strings:
env:
secure: SOMESTUFFuru4irlVd3Hd6c+x2joz6g=
secure: SOMESTUFFuru4gfgfgfgfgfggfgfgfHd6c+x2joz6g=
Than I added these keys to carrierwave.rb:
CarrierWave.configure do |config|
config.fog_credentials = {
provider: "AWS",
aws_access_key_id: Rails.application.secrets.aws_access_key,
aws_secret_access_key: Rails.application.secrets.aws_secret_key,
region: Rails.application.secrets.aws_region
}
config.fog_directory = "busketS3"
end
And pushed it on Github. But I got an error:
Missing required arguments: aws_access_key_id, aws_secret_access_key (ArgumentError)
My secrets.yml:
development:
facebook_key: "***********"
facebook_secret: "***************"
google_key: "***********************"
google_secret: "***********************"
aws_access_key: "***********************"
aws_secret_key: "***********************"
aws_region: "***********************"
test:
secret_key_base: "***********************"
aws_access_key: "***********************"
aws_secret_key: "***********************"
aws_region: "***********************"
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
What's wrong?
I think a problem in your secrets.yml:
secret_key_base: "***********************"
aws_access_key: "***********************"
^^^^^^^^^^^^^^
aws_secret_key: "***********************"
^^^^^^^^^^^^^^
aws_region: "***********************"
But keys should be, according error that you have:
Missing required arguments: aws_access_key_id, aws_secret_access_key
(ArgumentError)
not:
aws_access_key, aws_secret_access

mongodb speed on remote server [duplicate]

I have my Yaml configuration file, mongo.yml:
development:
adapter: mongodb
database: fhsclock_development
host: localhost
port: nil
test:
adapter: mongodb
database: fhsclock_test
host: localhost
port: nil
production:
adapter: mongodb
database: fhsclock
hosts:
- - localhost
- nil
- - staff.mongohq.com
- 10015
How do I use this file for configuration and connection with MongoMapper?
MongoMapper will just use the file if it's you're using Rails and the file is at config/mongo.yml. If you're not on Rails, you can adapt this code from the source:
config_file = Rails.root.join('config/mongo.yml')
if config_file.file?
config = YAML.load(ERB.new(config_file.read).result)
MongoMapper.setup(config, Rails.env, :logger => Rails.logger)
end
Also, the "adapter" in your file is extraneous. (See the Getting Started documentation). A mongo.yml from rails g mongo_mapper:config looks like:
defaults: &defaults
host: 127.0.0.1
port: 27017
development:
<<: *defaults
database: my_app_development
test:
<<: *defaults
database: my_app_test
# set these environment variables on your prod server
production:
<<: *defaults
database: my_app
username: <%= ENV['MONGO_USERNAME'] %>
password: <%= ENV['MONGO_PASSWORD'] %>

Mongoid Production Issue: Failed to connect to a master node

I've switched away from Mongo_Mapper to Mongoid and am having trouble deploying to production, for some reason. I'm using NGINX, Rails 3.1, and Passenger. I keep getting this message, "Failed to connect to a master node at myusernamehere:27017 (Mongo::ConnectionFailure)".
defaults: &defaults
host: localhost
# slaves:
# - host: slave1.local
# port: 27018
# - host: slave2.local
# port: 27019
development:
<<: *defaults
database: s3uploadergen_development
test:
<<: *defaults
database: s3uploadergen_test
production:
host: localhost
port: 27017
database: mydbnamehere
username: myuserhere
password: mypasswordhere
I've triple-checked all settings and tried the ENV approach as well (adding the ENV variables to production.rb and calling them via the documented mongoid approach but had the same issue):
production:
host: <%= ENV['MONGOID_HOST'] %>
port: <%= ENV['MONGOID_PORT'] %>
username: <%= ENV['MONGOID_USERNAME'] %>
password: <%= ENV['MONGOID_PASSWORD'] %>
database: <%= ENV['MONGOID_DATABASE'] %>
Ideally, I want to just specify it either in production.rb or an initializer of some sort.
I'm assuming that by "documented mongoid approach" you mean setting the recommended "uri" param instead of all those different setttings. You might want to try it since it's the recommended way of doing it.
defaults: &defaults
persist_in_safe_mode: true
development:
<<: *defaults
host: localhost
database: app_development
test:
<<: *defaults
host: localhost
database: app_test
production:
<<: *defaults
uri: <%= ENV['MONGOHQ_URL'] %>
Note that I do use Heroku but I don't use the MongoHQ add on. I just use it directly, so I manually set my MONGOHQ_URL. Your uri would look something like:
mongodb://<user>:<password>#<the.db.host.com>:<port>/<database_name>
Looks to me like you can't connect to "localhost" based on the error (like maybe you need the full host name or IP or something?). Anything in your app logs?
Just make sure not to set "host" and "uri" on any of the ENV's because "host" will override the setting that is derived from the uri.

S3.YML - Accessing a variable? based on the current Env?

I'm using paperclip which has a /config/s3.yml file with the following:
common: &common
access_key_id: XXXXXXXXXX
secret_access_key: XXXXXXXXXXXXXXXXXXXX
development:
<<: *common
bucket: myapp-local-dev
test:
<<: *common
bucket: myapp-123-test
production:
<<: *common
bucket: myappname-313-production
In my view I would like to dynamically be able to do something like this:
<img src="http://s3.amazonaws.com/myapp-local-dev/1/photos/15/1/thumb/Logo%20Design%20by%20kuda-1.jpeg" />
or
<img src="http://s3.amazonaws.com/myappname-313-production/1/photos/15/1/thumb/Logo%20Design%20by%20kuda-1.jpeg" />
Somehow, knowing the current environment and then getting the bucket name. Possible? thanks
YAML.load_file("#{Rails.root}/config/s3.yml")[Rails.env]["bucket"]
Should do the trick if you just want to return the bucket name.
If you're using Paperclip with aws/s3 this should be handled automatically though.
So:
<%= image_tag #my_obj.image.url %>
should return the desired url regardless of the environment
Hope that helps?

Resources