ruby-on-rails-5

ActionCable on AWS: Error during WebSocket handshake: Unexpected response code: 404

别等时光非礼了梦想. 提交于 2020-01-09 10:08:44
问题 We are attempting to deploy DHH's simple Rails 5 chat example to a single, self contained EC2 instance on AWS. Code is available here: https://github.com/HectorPerez/chat-in-rails5 We used Elastic Beanstalk to spin up a single instance thus: eb create dev-env -p “64bit Amazon Linux 2015.09 v2.0.4 running Ruby 2.2 (Puma)” –single -i t2.micro --envvars SECRET_KEY_BASE=g5dh9cg614a37d4bdece9126b42d50d0ab8b2fc785daa1e0dac0383d6387f36b This is a minimal installation, so there is no Elasticache, and

Consistently using associated model subclasses

谁说我不能喝 提交于 2020-01-07 09:47:14
问题 I have a situation where I have basic models that I want to add business logic to. For example, I might have something like this. class List < ApplicationRecord has_many :subscriptions has_many :subscribers, though: :subscriptions end class Subscriber < ApplicationRecord has_many :subscriptions has_many :lists, through: :subscriptions end class Subscription < ApplicationRecord belongs_to :list belongs_to :subscriber end Subscribing and unsubscribing is easy via the normal association methods.

How do I extract just a specific portion of a code snippet from multiple files, that may be different in different files

痴心易碎 提交于 2020-01-07 00:27:27
问题 So what I am doing is iterating over various versions of snippet of code (for e.g. Associations.rb in Rails). What I want to do is just extract one snippet of the code, for example the has_many method: def has_many(name, scope = nil, options = {}, &extension) reflection = Builder::HasMany.build(self, name, scope, options, &extension) Reflection.add_reflection self, name, reflection end At first I was thinking of just searching this entire file for the string def has_many and then saving

Why I got this object params array attached to my object result in view? [duplicate]

99封情书 提交于 2020-01-06 08:16:51
问题 This question already has answers here : What is the difference between <%, <%=, <%# and -%> in ERB in Rails? (7 answers) Closed 5 months ago . I have this object named @forum_posts which populate all my forum posts . And when I render this in the view, I got the results along with the array of it's params like shown below: Here is how i defined @forum_posts in the forum_posts.rb controller: @forum_posts = ForumPost.all And even if I defined it directly in the view by using ForumPost.all each

rails 5.1: nested form validation

天大地大妈咪最大 提交于 2020-01-06 07:12:23
问题 I have a parent model called user and 2 nested models called award and certification. when I go to save a certification the model validation for award tells me that awards is blank, and when I got to save an award I get an error that says the validations for certification is blank. not sure what's going on. here my user model has_many :certifications, dependent: :destroy has_many :awards, dependent: :destroy # allows for nested attributes in the user views. accepts_nested_attributes_for :work

Actioncable authentication with multiple Devise models

走远了吗. 提交于 2020-01-06 06:48:28
问题 I am currently implementing a chat between 2 of my Devise models. Client and Professionnel . It is working just fine at the moment but I have only one channel: every Client or Professionnel receive all messages from all clients and all professionals. The displaying is fine but someone who watches their AJAX flow can see every private message that is not meant for them.. As per this thread http://www.thegreatcodeadventure.com/rails-5-action-cable-with-multiple-chatroom-subscriptions/ this is

Actioncable authentication with multiple Devise models

半城伤御伤魂 提交于 2020-01-06 06:48:14
问题 I am currently implementing a chat between 2 of my Devise models. Client and Professionnel . It is working just fine at the moment but I have only one channel: every Client or Professionnel receive all messages from all clients and all professionals. The displaying is fine but someone who watches their AJAX flow can see every private message that is not meant for them.. As per this thread http://www.thegreatcodeadventure.com/rails-5-action-cable-with-multiple-chatroom-subscriptions/ this is

What's the difference between “left_joins” and “includes” in Rails 5?

僤鯓⒐⒋嵵緔 提交于 2020-01-06 05:35:06
问题 In Rails 5, they have added the ActiveRecord query method left_joins . What's the difference between left_joins and includes ? I've always seen includes as a left join. 回答1: includes by default loads the association data in 2 queries just like preload. But with additional references call it switches from using two separate queries to creating a single LEFT OUTER JOIN like left_joins. Refs: Preload, Eagerload, Includes and Joins Making sense of ActiveRecord joins, includes, preload, and eager

Rails, No 'Access-Control-Allow-Origin' header is present on the requested resource

我与影子孤独终老i 提交于 2020-01-05 09:35:27
问题 I have apps on Angular, which uses the server Ruby on Rails/oAuth backend. When registering a user in the console, I get these errors. POST*.herokuapp.com/api/users 500 (Internal Server Error) *.herokuapp.com/api/users:1 Failed to load *.herokuapp.com/api/users: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '*.herokuapp.com' is therefore not allowed access. The response had HTTP status code 500. /registration:1 { "isTrusted": true /auth.ts:95 } And other

View for admin in rails

江枫思渺然 提交于 2020-01-05 07:04:45
问题 I have a parent table, child Table, funding table. Parent logs in, add his children and then apply for funding for each child. parent.rb class Parent < ApplicationRecord has_many :children, dependent: :destroy has_many :secondaryparents, dependent: :destroy end funding.rb class Funding < ApplicationRecord has_many :organisations, dependent: :destroy belongs_to :child end child.rb class Child < ApplicationRecord belongs_to :parent has_many :fundings, dependent: :destroy end Parent has a field