I'm using octopus gem in my rails3 application.i added the below in my migration file,
class CreateUsers < ActiveRecord::Migration
using(:master, :slave1)
def self.up
create_table :users do |t|
t.string :name
t.integer :age
t.timestamps
end
end
def self.down
drop_table :users
end
end
Below is my shards.yml file
## YAML Template.
---
octopus:
environments:
- development
development:
slave1:
host: localhost
adapter: mysql
database: Octopus_development
Here slave1 database will be created by rails or do we need to create? Can anyone explain this? What should i do now?
You need to have the DB slave1 created before you run the migrations. The migration however will be run on both the master and the slave1.
Also you will prob have to setup slave1 as a replica of the master if you are going to use replication. If its only for sharding purpose then replication setup is not required.
Related
I have some Ruby on Rails applications that are using Active Admin gem. Rails version is 3.2.6, Active Admin version is 0.4.4.
I am pushing these applications to Heroku, then doing migrations and everything is working fine. But after some time (when application restarts) i'm starting to get 404 error when trying to open admin page (like myapp/admin). In logs there is an error:
ActionController::RoutingError (uninitialized constant Admin::DashboardController)
Moreover, if i'm trying to open some other admin page (like myapp/admin/videos - to administer videos) everything is still working fine, but error 404 persists when opening Dashboard page.
I have tried to put
config.cache_classes = true
config.assets.compile = true
to my config files, but all the same.
Basically the scheme is as follows:
I make some changes to the app, commit the changes with "git add .", "git commit" and push it to Heroku
I open the /admin page on Heroku and it works fine
After application restarts i get 404 error when visiting /admin, but everything still works when accessing other admin pages, not dashboard
GoTo 1
I'm still unsure if the error appears when the app is restarted by itself (not by "heroku restart").
Any ideas why this is happening? Maybe someone can advice how to switch off this Dashboard and use my myapp/admin/videos as the default admin page?
I had this very same problem, and since it complaints about the ActiveAdmin Dashboard, and it is now deprecated I proceeded to update my dashboard.rb file to the new Dashboard style and that solved the problem.
(I got that file from here).
Hope it helps.
I got the same issue.
Check whether you have to upgrade ActiveAdmin to new version
When upgrading to a new version of ActiveAdmin you may need to run
rails generate active_admin:assets
If you get:
uninitialized constant Admin::DashboardController
Use the New default page for admin/dashboard.rb
which is like following,
ActiveAdmin.register_page "Dashboard" do
menu :priority => 1, :label => proc{ I18n.t("active_admin.dashboard") }
content :title => proc{ I18n.t("active_admin.dashboard") } do
div :class => "blank_slate_container", :id => "dashboard_default_message" do
span :class => "blank_slate" do
span I18n.t("active_admin.dashboard_welcome.welcome")
small I18n.t("active_admin.dashboard_welcome.call_to_action")
end
end
# Here is an example of a simple dashboard with columns and panels.
#
# columns do
# column do
# panel "Recent Posts" do
# ul do
# Post.recent(5).map do |post|
# li link_to(post.title, admin_post_path(post))
# end
# end
# end
# end
# column do
# panel "Info" do
# para "Welcome to ActiveAdmin."
# end
# end
# end
end # content
end
Newly signed up users to my little app must be approved by the admin (me) before they can gain access to the site. I've succeeded in generating such emails in development with an after_create :send_admin_email in my user model which works great. My problem is that I'm generating multiple users during my tests (using FactoryGirl) and each test user created sends off a real email. Running my tests is like pouring molasses in January and I've got to delete hundreds of emails sent to my inbox. How do I turn that off?
Action Mailer Basics in the Rails Guides tells me that "By default Action Mailer does not send emails in the test environment. They are just added to the ActionMailer::Base.deliveries array."
Moreover, in config/environments/test.rb I've got:
config.action_mailer.delivery_method = :test
That's in addition to in config/environment.rb having:
# Configuration for using SendGrid on Heroku
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => 'app[my app number]#heroku.com',
:password => '[something super secret]',
:domain => '[let's get this party started!.com]',
:enable_starttls_auto => true
}
ActionMailer::Base.delivery_method = :smtp
I'm sure that I'm missing something simple and basic. I've searched around and related questions and posts deal with how to test that ActionMailer actually sent email.
Humble gratitude in advance for any thoughts or help.
Addendum: Following answer to similar question found at Is it possible to turn off ActionMailer emails when cucumber testing is happening on development? I was able to stop the email sending madness. Still, I had to add ActionMailer::Base.delivery_method = :test to several rspec files. Is there a way I can shut this down globally? Anyone have any thoughts on what's going on?
So I've figured it out. Having the line ActionMailer::Base.delivery_method = :smtp in config/environment.rb overrides ActionMailer::Base.delivery_method = :test in config/environments/test.rb.
So, delete that line, ActionMailer::Base.delivery_method = :smtp'
from config/environment.rb and place it in config/environments/production.rb.
That allows you to place ActionMailer::Base.delivery_method = :test in config/environments/test.rb and the version you want in config/environments/development.rb. I made development.rb :test as I populated my database using Faker and changed it to smtp so I was sure that real emails were sent as an additional check.
Note: You must restart your server for these changes to take effect.
Another note: Heroku's current SendGrid Instructions put the SendGrid Heroku configuration code in a new config/initializers/mail.rb file which will likely require removing its last line and placing the desired version in each config/environments/[production.rb, development.rb, test.rb]
Perhaps useful...
My config/environment.rb did not contain ActionMailer::Base.delivery_method = :smtp and my config/environments/test.rb did contain ActionMailer::Base.delivery_method = :test but Rails still delivered mailers while testing.
I simply added the following to config/environments/test.rb to fix:
config.action_mailer.perform_deliveries = false
I faced the similar situation in Rails4.2 (ActiveJob integration with ActionMailer) even if I didn't write delivery_method = :smtp in config/environment.rb.
In my case, The issue here happened after using "resque" as background worker. Finally, I found out that the following config was WRONG:
config/initializers/active_job.rb:
Rails.application.config.active_job.queue_adapter = :resque # here is WRONG
...because it effected to test mode as well.
So, I set "queue_adapter = :resque" only in config/environments/{development,production.rb}. Now, that works as I expect.
I'm using RSpec, Spork, Capybara and Capybara Mechanic to write integration tests for a registration path that uses Facebook connect. It correctly navigates through registration, but the new users are created in my development database instead of the test database.
RSpec is setup to use the test environment and I've confirmed that any model methods I run in my spec all hit the test database, but all of the UI actions hit development.
Here's my test:
it "go through registration path" do
print "RAILS_ENV: #{Rails.env}\n" # correctly prints 'test'
print "1) #{User.count}\n" # correctly shows the user count in my test database (zero)
Capybara.current_driver = :mechanize
visit root_path
click_link "register"
# Fill in Facebook Connect form
fill_in 'email', :with => "bob#example.com"
fill_in 'pass', :with => "password"
click_button "Log In"
print "2) #{User.count}\n" # still shows zero users in the test database
end
After that test I can look at my development database and the new user has been created there.
I've tried setting up database_cleaner as well and that hasn't helped.
Anyone know what I need to do so that capybara will hit the test database?
rails 3.1.3
rspec 2.7.0
spork 0.9.0
capybara 1.1.0
capybara-mechanize 0.3.0.rc3
The problem was that I had a separate development server running in parallel with the tests and the tests were defaulting to a the same address/port. I resolved this by adding the following to spec_helper.rb so Capybara would use a different port.
Capybara.run_server = true
Capybara.server_port = 7000
Capybara.app_host = "http://localhost:#{Capybara.server_port}"
I have some Cucumber features which need to interact with the Google Maps Routing API. I'm trying to stub out these interactions using VCR.
I have added a VCR tag to my features like so:
#google_routing_api #javascript
Scenario: Creating a bus
Given I am on the buses page
When I follow "Get Started Now"
And then added my VCR configuration in features/support/vcr.rb
require 'vcr'
VCR.config do |c|
# INFO: This is relative to the Rails.root
c.cassette_library_dir = 'features/fixtures/vcr_cassettes'
c.stub_with :fakeweb
end
# INFO: https://github.com/myronmarston/vcr/wiki/Usage-with-Cucumber
VCR.cucumber_tags do |t|
t.tag '#google_routing_api'
end
But when I run my cukes, I am told..
Real HTTP connections are disabled. Unregistered request: GET http://127.0.0.1:54181/__identify__
You have to set VCR to ignore localhost requests. Otherwise, when capybara tries to request any page from your website, VCR will block it.
Add c.ignore_localhost = true to your VCR config block.
VCR.config do |c|
c.cassette_library_dir = 'features/fixtures/vcr_cassettes'
c.stub_with :fakeweb
c.ignore_localhost = true
end
I'm using:
Paperclip 2.3.16
Rails 3.0.9
Ruby 1.9.2
AWS - S3 0.6.2
I'm trying to use paperclip the upload to the EU (Ireland) based bucket. I have the following in my model:
has_attached_file :image, :styles => { :grid => '90x128#', :list => '140x200#', :original => '400x548'},
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:url => 'flyers/:id/:style/:basename.:extension',
:path => 'flyers/:id/:style/:basename.:extension',
:bucket => 'fsight'
In my environment.rb I have set the write to use the AWS/s3 Default Host to the relevant EU one by using:
require "aws/s3"
AWS::S3::DEFAULT_HOST.replace "s3-eu-west-1.amazonaws.com"
This works fine, and it allows me to upload the images, and I can verify the image upload / delete using the AWS Management consoler.
However, I have a problem when trying to display the images on my site. The images do not load and I have identified the cause, as the URL generated uses the old default host. Eg:
What it should be:
https://s3-eu-west-1.amazonaws.com/fsight/flyers/50/full/4759543368588654950.jpg
What it actually is: http://s3.amazonaws.com/fsight/flyers/50/full/4759543368588654950.jpg?1314801178
As you can see, it uses the old default host.
I tried placing:
Paperclip.interpolates(:s3_eu_url) do |att, style|
"#{att.s3_protocol}://s3-eu-west-1.amazonaws.com/#{att.bucket_name}/#{att.path(style)}"
end
But then started receiving the following error:
wrong number of arguments (0 for 1)
Extracted source (around line #9):
<img src= <%= #event.image.url(:original) %>
I know Paperclip has some issues with using EU Buckets, but could anybody help me with this?
You don't need to work around the EU Problem anymore.
The default aws-s3 storage backend in paperclip was replaced by the AWS SDK for Ruby, that is also the amazon recommended way when working with AWS.
Just insert
gem 'aws-sdk'
into your Gemfile and run bundle install.
If you want something like https://s3-eu-west-1.amazonaws.com/some_path_goes_here, try to configure your model's has_attached_file with the following options
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:s3_permissions => :private,
:s3_protocol => 'https',
:s3_host_name => 's3-eu-west-1.amazonaws.com',
:path => ":filename"
If you don't want to use https you can remove the :s3_protocol and if you want to change the region, option :s3_host_name is the right way to go. You can also put this into a configuration file.
Hope this helps.
Did you try this workaround?
Paperclip et les European S3 buckets
Or even this one?
Paperclip, S3, and European Buckets
I added
Paperclip::Attachment.default_options[:s3_host_name] = 's3-eu-west-1.amazonaws.com'
to paperclip.rb in the initializers folder and it works fine for me.
Same problem here, just solved passing the following option to has_attached_file:
:url => ':s3_domain_url'
For more info see here http://rubydoc.info/gems/paperclip/Paperclip/Storage/S3 :
Normally, this won't matter in the slightest and you can leave the default (which is path-style, or :s3_path_url). But in some cases paths don't work and you need to use the domain-style (:s3_domain_url).