ruby-on-rails-4

how to access multiple databases in single rails application in rails 4?

杀马特。学长 韩版系。学妹 提交于 2020-01-14 10:23:15
问题 I am new to rails, don't know how to access multiple databases in rails single application. I will try like this config/database.yml default: &default adapter: mysql2 encoding: utf8 pool: 5 username: root password: root socket: /var/run/mysqld/mysqld.sock reconnect: true development: <<: *default database: connection_development <<: *default database: connection_test second database log_database_production: adapter: mysql2 encoding: utf8 pool: 5 host: 192.168.100.97 port: 3306 #ip address of

Handle dependent destroy via active jobs

天大地大妈咪最大 提交于 2020-01-14 09:35:07
问题 I have a couple models with many children. Dependent destroy has gotten really heavy. Anyone know of a way to tie dependent destroy into active jobs? Or, is my only option to remove dependent destroy and role my own jobs via callbacks on the parent model? 回答1: You can create a worker to destroy the models async and enqueue it's deletion. Something like: class ComplexModelDeletion < ActiveJob::Base def perform(model) model.destroy! end end And the model could be something like: class Model <

Make existing column unique in Rails

旧巷老猫 提交于 2020-01-14 08:18:12
问题 I have username column on users table. I could do somethig like this: rails generate migration add_username_to_users username:string:uniq but I have got username column (and I've already run migration). So how can I make username column unique? 回答1: It's not very clear if you want to ensure the values in username are unique, or if you want to filter existing values to be unique. At database level, the way you ensure uniqueness is via indexes. In a migration, create a new unique index for the

Make existing column unique in Rails

╄→尐↘猪︶ㄣ 提交于 2020-01-14 08:17:03
问题 I have username column on users table. I could do somethig like this: rails generate migration add_username_to_users username:string:uniq but I have got username column (and I've already run migration). So how can I make username column unique? 回答1: It's not very clear if you want to ensure the values in username are unique, or if you want to filter existing values to be unique. At database level, the way you ensure uniqueness is via indexes. In a migration, create a new unique index for the

How to solve has an integrity attribute issue on bootstrap.min.css

断了今生、忘了曾经 提交于 2020-01-14 07:21:13
问题 I am using bootstrap icons in my project which gives me error Subresource Integrity: The resource 'http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css' has an integrity attribute, but the resource requires the request to be CORS enabled to check the integrity, and it is not. The resource has been blocked because the integrity cannot be enforced. Can any one help me to solve this issue and when we move to production the icon is not loaded. So I am using below link for

How to solve has an integrity attribute issue on bootstrap.min.css

亡梦爱人 提交于 2020-01-14 07:21:09
问题 I am using bootstrap icons in my project which gives me error Subresource Integrity: The resource 'http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css' has an integrity attribute, but the resource requires the request to be CORS enabled to check the integrity, and it is not. The resource has been blocked because the integrity cannot be enforced. Can any one help me to solve this issue and when we move to production the icon is not loaded. So I am using below link for

Heroku Rails 4— FileNotFound jquery.ui.all

泄露秘密 提交于 2020-01-14 06:10:15
问题 I am running my app on my local server with no issues, and have been pushing to Heroku with no issues until now. I am suddenly seeing this error: Running: rake assets:precompile rake aborted! Sprockets::FileNotFound: couldn't find file 'jquery.ui.all' My gemfile: gem 'jquery-rails' gem 'jquery-ui-rails' My application.js : //= require jquery //= require jquery_ujs //= require jquery.turbolinks //= require turbolinks //= require bootstrap //= require_tree ./ //= require jquery.ui.all Let me

Heroku Rails 4— FileNotFound jquery.ui.all

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-14 06:09:28
问题 I am running my app on my local server with no issues, and have been pushing to Heroku with no issues until now. I am suddenly seeing this error: Running: rake assets:precompile rake aborted! Sprockets::FileNotFound: couldn't find file 'jquery.ui.all' My gemfile: gem 'jquery-rails' gem 'jquery-ui-rails' My application.js : //= require jquery //= require jquery_ujs //= require jquery.turbolinks //= require turbolinks //= require bootstrap //= require_tree ./ //= require jquery.ui.all Let me

Migration to create default value

非 Y 不嫁゛ 提交于 2020-01-14 05:50:09
问题 So I want to know whether we can write a new migration just to set default value of a field,which is already created. I know how to write edit the old migration and set its default value. I want to do this because I have done so many migrations and I cant roll back now and edit that file. And also, Is there any way to rollback to a particular migration? Thanks in advance 回答1: Run rails g migration add_default_value_to_table then in the migration file def up change_column :table_name, :column

rails has_one relationship causing problems - also white screen

孤街浪徒 提交于 2020-01-14 05:45:07
问题 I have two models: Schedule and Project. Schedule belongs_To Project and Project has_one schedule. There are several problems, but i think they all have the same cause. Here is the code for the schedules#create controller: def create @schedule = Schedule.new(schedule_params) @schedule.project = Project.find(params[:project_id]) if @schedule.project.student_id == current_user.id if @schedule.save && @schedule.freelancer_accepts flash[:notice] = "Successfully created schedule." redirect_to