ruby-on-rails-5

Rails 5 Action Cable deployment with Nginx, Puma & Redis

為{幸葍}努か 提交于 2019-12-22 03:42:06
问题 I am trying to deploy an Action Cable -enabled-application to a VPS using Capistrano. I am using Puma, Nginx, and Redis (for Cable). After a couple hurdles, I was able to get it working in a local developement environment. I'm using the default in-process /cable URL. But, when I try deploying it to the VPS, I keep getting these two errors in the JS-log: Establishing connection to host ws://{server-ip}/cable failed. Connection to host ws://{server-ip}/cable was interrupted while loading the

Disable rails log for ActionCable events

流过昼夜 提交于 2019-12-22 03:16:48
问题 In development environment, rails logger logs all ActionCable events which is sometimes annoying (for my project, every now and then it's transmitting messages and log tail is running like wild horse). What is an efficient way to suppress all event logs from ActionCable? Also, how can I suppress some specific ActionCable events? 回答1: To completely disable logging from ActionCable you should configure ActionCable to use logger that do nothing ActionCable.server.config.logger = Logger.new(nil)

Catching Invalid JSON Parse Errors with Rack Middleware

不打扰是莪最后的温柔 提交于 2019-12-21 12:57:52
问题 I am using Rails 5 and I am trying to improve error handling for invalid JSON requests to my API. I tried handling invalid format JSON by parsing in the controller with a rescue but realised that Rails middleware is parsing my JSON request before it hits the controller if a user adds Content Type to their request header. I followed the below guide: https://robots.thoughtbot.com/catching-json-parse-errors-with-custom-middleware However, I get the following error when starting the server:

Belongs_to presence in Rails 5 not working

蓝咒 提交于 2019-12-21 09:35:26
问题 To my knowledge, the new default in Rails 5 requires belongs_to associations to be present. I made a model with this association, but the problem is I don't get presence validation error when the associated field is empty. Instead I get a database Null Validation error since I set the _id column not to be null. (PG::NotNullViolation because I use Postgres) Is this behaviour normal? I mean shouldn't I get the rails error only? BTW, when I add presence validation for the field, it works as I

require_tree argument must be a directory in a Rails 5 upgraded app

心已入冬 提交于 2019-12-20 16:47:29
问题 I just upgraded my app from Rails 4.2.7 to Rails 5.0.0.1 . I used RailsDiff to make sure I had everything covered and I believe I did. So far everything has worked well up until the loading of my app. Now I am seeing this error: Sprockets::ArgumentError at / require_tree argument must be a directory This is my application.css : /* * This is a manifest file that'll be compiled into application.css, which will include all the files * listed below. * * Any CSS and SCSS file within this directory

How to configure ActionCable with Nginx and Unicorn in production?

醉酒当歌 提交于 2019-12-20 10:58:13
问题 I've recently switched my rails project from Rails4 to 5.0.0.beta3 to use the awesome ActionCable. My ActionCable server is run inside unicorn. In development all works fine. In production I have Started GET "/cable" for xxx.xxx.xxx.xxx at 2016-03-28 18:06:38 +0300 Started GET "/cable/" [WebSocket] for xxx.xxx.xxx.xxx at 2016-03-28 18:06 Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket) Registered connection (189772ff-6229-48f1-ae7f

Ruby Nested Form

萝らか妹 提交于 2019-12-20 06:43:57
问题 Actually, On saving it must save, but i am getting error and tried to figure out the error where i did mistake. Kindly help me with this error. Thanks in Advance. Controller def new @fooditem = Fooditem.new 3.times { @fooditem.fooditemprices.build} end #Creating Food Items def create @fooditem = Fooditem.new(fooditem_params) if @fooditem.save flash[:success] = "Food item created successfully." redirect_to fooditems_path else render 'new' end end Model(s) class Fooditem < ApplicationRecord has

Heroku rake db:migrate does not create tables (Rails 5)

不问归期 提交于 2019-12-20 05:42:06
问题 I have a Rails 5 app and I wanted to destroy and rebuild my live database (site not launched yet). So I followed the steps that should've worked (they used to work in the past): heroku pg:reset HEROKU_POSTGRESQL_HEROKUCOLOR_URL --confirm {app_name} heroku run rake db:migrate heroku run rake db:seed Steps 1 & 2 complete successfully and step 3 fails with the error ('adminsettings' is one of my tables): Running rake db:seed on {app_name}... starting, run.7198 (Hobby) Running rake db:seed on

Heroku rake db:migrate does not create tables (Rails 5)

浪尽此生 提交于 2019-12-20 05:41:40
问题 I have a Rails 5 app and I wanted to destroy and rebuild my live database (site not launched yet). So I followed the steps that should've worked (they used to work in the past): heroku pg:reset HEROKU_POSTGRESQL_HEROKUCOLOR_URL --confirm {app_name} heroku run rake db:migrate heroku run rake db:seed Steps 1 & 2 complete successfully and step 3 fails with the error ('adminsettings' is one of my tables): Running rake db:seed on {app_name}... starting, run.7198 (Hobby) Running rake db:seed on

uninitialized constant Rack::Session::Abstract::Persisted to start Rails 5 server

无人久伴 提交于 2019-12-20 04:19:47
问题 I am getting this error while running command rails s => Booting Thin => Rails 5.0.0.1 application starting in development on http://localhost:3000 => Run `rails server -h` for more startup options Exiting /var/lib/gems/2.2.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/session/abstract_store.rb:90:in `<module:Session>': uninitialized constant Rack::Session::Abstract::Persisted (NameError) from /var/lib/gems/2.2.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/session