ruby-on-rails-5

Add a reference column migration in Rails 5

跟風遠走 提交于 2020-02-20 06:21:09
问题 A user has many uploads. I want to add a column to the uploads table that references the user. What should the migration look like? Related question for Rails 3: Rails 3 migrations: Adding reference column? Related question for Rails 4: Add a reference column migration in Rails 4 回答1: As with prior versions of Rails, you may use the following command to create the migration: rails g migration AddUserToUploads user:references Unlike prior versions of Rails, the migration looks like: class

Heroku with rails 5 error Gem::LoadError: Specified 'postgresql' for database adapter

ぃ、小莉子 提交于 2020-02-10 04:27:08
问题 I am a Rails beginner and i see some issue while deploying to Heroku. Earlier i used SQLite3, later when i understood that i needed postgresql i installed the same and work on local machine. One deployment went fine after migrating from sqlite to postgresql. Now i see some issue. Heroku logs, Gem file and Database.yml details are as below. Can some one help me in this please. Advance Thanks...!!! Part of Gem file: group :development, :test do gem 'pg', '~> 1.0.0' gem 'rails_12factor' #gem

Heroku with rails 5 error Gem::LoadError: Specified 'postgresql' for database adapter

牧云@^-^@ 提交于 2020-02-10 04:26:25
问题 I am a Rails beginner and i see some issue while deploying to Heroku. Earlier i used SQLite3, later when i understood that i needed postgresql i installed the same and work on local machine. One deployment went fine after migrating from sqlite to postgresql. Now i see some issue. Heroku logs, Gem file and Database.yml details are as below. Can some one help me in this please. Advance Thanks...!!! Part of Gem file: group :development, :test do gem 'pg', '~> 1.0.0' gem 'rails_12factor' #gem

Login using Outlook showing cookie overflow error

巧了我就是萌 提交于 2020-02-06 19:00:33
问题 I am implementing outlook signup/signin in my Rails app for authentication from scratch without using Devise or another library or gem. I have followed the official microsoft blog For integrating outlook signin in Rails app But I am failing to implement the final step and it shows-> I have understood the problem , that the storing size of token exceeds the available cookie size I have successfully done all of the steps just When I try to store the token, it gives error class AuthController <

Login using Outlook showing cookie overflow error

元气小坏坏 提交于 2020-02-06 19:00:11
问题 I am implementing outlook signup/signin in my Rails app for authentication from scratch without using Devise or another library or gem. I have followed the official microsoft blog For integrating outlook signin in Rails app But I am failing to implement the final step and it shows-> I have understood the problem , that the storing size of token exceeds the available cookie size I have successfully done all of the steps just When I try to store the token, it gives error class AuthController <

How can I test ActionCable using RSpec?

心已入冬 提交于 2020-02-06 07:34:11
问题 This is my NotificationChannel class NotificationChannel < ApplicationCable::Channel def subscribed stream_from "notification_user_#{user.id}" end def unsubscribed stop_all_streams end end How can I write test for this ActionCable channels This is my Rspec require 'rails_helper' require_relative 'stubs/test_connection' RSpec.describe NotificationChannel, type: :channel do before do @user = create(:user) @connection = TestConnection.new(@user) @channel = NotificationChannel.new @connection, {}

Why Rails fails to detect AJAX request in production?

故事扮演 提交于 2020-02-02 12:29:04
问题 The bounty expires in 5 days . Answers to this question are eligible for a +100 reputation bounty. simo is looking for an answer from a reputable source : “I tried every thing I can, but nothing worked..” I am using rails 5.2.4.1, and I am wondering why I get this error when I try to access the API endpoint: ActionView::MissingTemplate (Missing template api/schools/classrooms , application/classrooms with {:locale=>[:en], :formats=>[:json], :variants=>[], :handlers=>[:raw, :erb, :html,

How to write a migration to convert an already-present association to optional?

这一生的挚爱 提交于 2020-01-30 08:12:57
问题 I have a few belongs_to migrations created&migrated but I see now that in Rails 5, the default behavior is required: true which I do not want. My question is that how can I write a simple migration to convert that to optional: true ? Can't find this particular solution anywhere. 回答1: You can use the change_column_null method for that: def change change_column_null :table, :column, true end change_column_null is reversible, if you need to rollback the value will be false (or true depending on

How to write a migration to convert an already-present association to optional?

99封情书 提交于 2020-01-30 08:12:06
问题 I have a few belongs_to migrations created&migrated but I see now that in Rails 5, the default behavior is required: true which I do not want. My question is that how can I write a simple migration to convert that to optional: true ? Can't find this particular solution anywhere. 回答1: You can use the change_column_null method for that: def change change_column_null :table, :column, true end change_column_null is reversible, if you need to rollback the value will be false (or true depending on

Spring and middleware conflict?

半世苍凉 提交于 2020-01-29 09:48:28
问题 I'm trying to add oauth2 with Google, following these instructions. I'm receiving the following error message starting the server: Exiting You've tried to invoke Spring when it's already loaded (i.e. the Spring constant is defined). This is probably because you generated binstubs with Spring 1.0, and you now have a Spring version > 1.0 on your system. To solve this, upgrade your bundle to the latest Spring version and then run `bundle exec spring binstub --all` to regenerate your binstubs.