I am working on a MVC project in Ruby on Rails. I have the actual code and i have to understand it in next few days and then try to upgrade it.
I have a home-page with a textbox which ask you the e-mail for resistration. The problem is that when i push the submit button it gives me
Recaptcha::Recaptcha Error - No site key specified
I know that there are many posts about this problem but i don't manage to resolve it.
Here is my .env file
RECAPTCHA_SITE_KEY=6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy
RECAPTCHA_SECRET_KEY=6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx
OMNIAUTH_PROVIDER_KEY=false
OMNIAUTH_PROVIDER_SECRET=false
ADMIN_NAME=false
SECRET_KEY_BASE=false
GA_PROVIDER_KEY=false
TWILIO_SID=false
TWILIO_TOKEN=false
TWILIO_NUMBER=false
Please help me with this.
You need to configure recaptcha to pull the keys from your secrets.yml by adding an initializer file, config/initializers/recaptcha.rb:
# config/initializers/recaptcha.rb
Recaptcha.configure do |config|
config.site_key = Rails.application.secrets[:RECAPTCHA_SITE_KEY]
config.secret_key = Rails.application.secrets[:RECAPTCHA_PRIVATE_KEY]
# Uncomment the following line if you are using a proxy server:
# config.proxy = 'http://myproxy.com.au:8080'
end
End in secrets.yml RECAPTCHA_SITE_KEY and RECAPTCHA_PRIVATE_KEY make sure that it is written in capital letters
Related
I'm using SendGrid(Node.js) for one of my personal projects. I followed the integration guide to set up my API KEY .env file as following:
echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
echo "sendgrid.env" >> .gitignore
source ./sendgrid.env
My question is... Every time before running the backend locally, I have to first run
source ./sendgrid.env
In order for the process.env.YOUR_API_KEY be acknowledged where the key is.
But after renamed the sendgrid.env file to just .env, I don't have to run source anymore.
This is how I call the API KEY
require('dotenv').config()
const { validationResult } = require('express-validator')
const Appointment = require('../models/Appointment')
const User = require('../models/User')
const sgMail = require('#sendgrid/mail')
sgMail.setApiKey(process.env.SENDGRID_API_KEY)
PS. I have set the dotenv config at the top of the file but still getting undefined until I changed the file name.
Does anyone know the reason or the logic behind this??
Thank you :)
If I am understanding it well enough. You have to change it to .env because by default require('dotenv').config() point to .env because the parenthesis of config are empty.
To follow the sendgrid way by calling your file sendgrid.env you would have to require('dotenv').config(sendgrid.env) and maybe, just require('dotenv').config(sendgrid) would be enough. Got to try it to know for sure. But at least from my understanding this is your answer.
I try to setup Amazon S3 support to store images in the cloud with refinerycms.
I created the bucket at https://console.aws.amazon.com/s3/
I named it like the app 'bee-barcelona' and it says it is in region US Standard
In ~/config/initializers/refinery/images.rb I entered all the data (where 'xxx? stands for the actual keys I entered:
# Configure S3 (you can also use ENV for this)
# The s3_backend setting by default defers to the core setting for this but can be set just for images.
config.s3_backend = Refinery::Core.s3_backend
config.s3_bucket_name = ENV['bee-barcelona']
config.s3_access_key_id = ENV['xxx']
config.s3_secret_access_key = ENV['xxx']
config.s3_region = ENV['xxx']
Then I applied the changes to heroku with:
heroku config:add S3_KEY=xxx S3_SECRET=xxx S3_BUCKET=bee-barcelona S3_REGION=us-standard
But still, in the app I only get: "Sorry, something wen wrong" when I try to upload.
What did I miss?
What a sad error. I didn't think about that option till I went for a 10 km run…
I had the app set up to be "beekeeping"
My bucket on Amazon was named "bee-barcelona"
I did register the correct bucket in the app. Still refinery tried to keep on going to another persons bucket, named "beekeeping". With my secret key there was no way my files would end up there.
I created a new app and a new bucket, all with crazy names, BUT! They are the same on AmazonS3 and GIT!!!
No it works like a charm.
What a very rare situation...
The way I did it was as follows:
Create a bucket in region US-STANDARD!!!!!!!!!!
Did you see that? US-STANDARD, not oregon, not anywhere else.
Add gems to Gemfile
gem "fog"
gem "unf"
gem "dragonfly-s3_data_store"
In config/application.rb
config.assets.initialize_on_precompile = true
In config/environments/production.rb
Refinery::Core.config.s3_backend = true
In config/environments/development.rb
Refinery::Core.config.s3_backend = false
Configure S3 for heroku (production) and local storage for development. In config/initializers/refinery/core.rb
if Rails.env.production?
config.s3_backend = true
else
config.s3_backend = false
end
config.s3_bucket_name = ENV['S3_BUCKET']
config.s3_region = ENV['S3_REGION']
config.s3_access_key_id = ENV['S3_ACCESS_KEY']
config.s3_secret_access_key = ENV['S3_SECRET_KEY']
Add variables to heroku:
heroku config:add S3_ACCESS_KEY=xxxxxx S3_SECRET_KEY=xxxxxx S3_BUCKET=bucket-name-here S3_REGION=us-east-1
I had a lot of issues because I had before S3_REGION=us-standard. This is WRONG. Set your US-Standard bucket as shown:
S3_REGION=us-east-1
This worked flawlessly for me on Rails 4.2.1 and refinery 3.0.0. Also, make sure you are using the exact same names for the variables. Sometimes it says S3_KEY instead of S3_ACCESS_KEY or S3_SECRET instead of S3_SECRET_KEY. Just make sure you have the same ones in your files and your Heroku variables.
I try to load a yaml file into an array but it fails with undefined method `join' for "a b c":String
# Check certain temporarily emails
# Throw notice not accepted use other email
require 'yaml'
bad_hostnames = YAML::load(File.read("#{Rails.root}/config/bad_hosts.yml"))
if /^(#{bad_hostnames.join("|")})$/.match(host)
errors.add(:email, "Please not use a disposable mailbox")
end
So i required yaml before and on top of the model, controller where I load the yml in:
require 'yaml'
Still same result, in rails console this works flawlessly, what am I missing?
The above code is inside my user.rb model, in console it works
EDIT:
bad_hosts.yml looks like (shortened) 1 provider the line
0-mail.com
10minutemail.com
30minutemail.com
4warding.net
Your .yml file is not a YAML file.
This would make it .yml file.
- 0-mail.com
- 10minutemail.com
- 30minutemail.com
- 4warding.net
But when you want to load just a file line by line try the following:
lines = IO.readlines("#{Rails.root}/config/bad_hosts.yml")
# note: lines end in "\n"
I have an app that works fine in on my development machine, but on my production server it uses a broken link to serve an image served using the Paperclip Gem.
Production environment is Linux(Debian), Apache, Passenger and I am deploying with Capistrano.
The app is stored in (a symlink that points to the public folder of the current version of the app deployed using capistrano):
/var/www/apps/root/appname
However, when I try and access it on the production server, the Apache error log displays this as the path it is looking in:
/var/www/apps/root/system
The correct path, however, is:
/var/www/apps/appname/shared/system
One option available to me is to create a symlink in root that directs system to the correct path, but I don't want to do this in case I want to deploy another app in the same root dir.
The url for this request is generated by rails, but Apache is what fetches the static resource (image files), so I have tried placing the following in my config/environments/production.rb:
ENV["RAILS_RELATIVE_URL_ROOT"] = '/appname/'
Which has resolved all other pathing issues I've been experiencing, but when rails generates the url (via the Paperclip gem), it doesn't seem to use it.
How can I set it so Paperclip uses the right path and only uses it production?
I've a workaround, add this as one of initializers:
config/initializer/paperclip.rb
Paperclip::Attachment.class_eval do
def url(style_name = default_style, options = {})
if options == true || options == false # Backwards compatibility.
res = #url_generator.for(style_name, default_options.merge(:timestamp => options))
else
res = #url_generator.for(style_name, default_options.merge(options))
end
# replace adding uri before res, minus final /
Rails.application.config.site_relative_url[0..-2]+res
end
end
At the moment Paperclip doesn’t work with ENV['RAILS_RELATIVE_URL_ROOT'] and the. You can follow the issue here:
https://github.com/thoughtbot/paperclip/issues/889
I'm new to rails, and looking to set up a site that uses Amazon's product API. I'm used to using the API in PHP but keen to move to Ruby if at all possible.
I've been trying the various Amazon product API gems, Ruby/AWS, Amazon-ECS, and now Vacuum. However a problem I am sticking at is how to actually use the code they suggest in their readme files.
For example, Vacuum:
https://github.com/hakanensari/vacuum/
It mentions the following code:
req = Vacuum.new :product_advertising
req.configure do |config|
config.key 'key'
config.secret 'secret'
config.tag 'tag'
end
req.build operation: 'ItemSearch',
search_index: 'Books',
keywords: 'Deleuze'
res = req.get
res.valid? or raise res.code
p res.body
Unsure where to put this code, I set up a controller for the test app and put it there. However it fails on the first line, saying that Vacuum is not defined (it's installed as a gem within the gemfile, and I've run bundle install).
I'm probably doing something stupid yet simple to fix, and would really appreciate any suggestions.
D
Edit:
Thanks to x1a4, the following code should be replace the configure block above:
req.configure do |config|
config.key = 'key'
config.secret = 'secret'
config.tag = 'tag'
end
Thanks to x1a4, the following code should be replace the configure block above:
req.configure do |config|
config.key = 'key'
config.secret = 'secret'
config.tag = 'tag'
end