ruby-on-rails-5

Rails: belongs_to with conditions/scope throwing syntax error

元气小坏坏 提交于 2019-12-20 03:52:20
问题 I want to pick companies that are owned. I tried multiple combinations, new, rails 3, old school,... all of which are throwing the same syntax error unexpected '\n', expecting => belongs_to :from, class_name: 'Company', foreign_key: 'from_id', -> { where owned: true } belongs_to :from, class_name: 'Company', foreign_key: 'from_id', -> { where(owned: true) } belongs_to :from, class_name: 'Company', foreign_key: 'from_id', -> { where(:owned => true) } belongs_to :from, class_name: 'Company',

Divide large routes.rb to multiple files in Rails 5

本小妞迷上赌 提交于 2019-12-19 19:53:46
问题 I want to upgrade my rails 4 app to 5.0.0.beta2. Currently I divided the routes.rb file to multiple files by setting config.paths["config/routes.rb"] e.g., module MyApp class Application < Rails::Application config.paths["config/routes.rb"] .concat(Dir[Rails.root.join("config/routes/*.rb")]) end end It seems rails 5.0.0.beta2 also exposes config.paths["config/routes.rb"] but the above code doesn't work. How can I divide routes.rb file in rails 5? 回答1: you can write some codes in config

heroku /usr/bin/env: ‘ruby.exe\r’: No such file or directory problem

霸气de小男生 提交于 2019-12-19 10:46:16
问题 So I have been deploying my app to the same heroku server for the past few weeks and it has been working great. I just tried to deploy my latest code and got this error when trying to run: heroku run rails db:migrate The error I got was this: /usr/bin/env: ‘ruby.exe\r’: No such file or directory problem I have looked at many other threads concerning this problem and taken their advice. The most common answer was to change the first line of the bin/bundle, bin/rails and bin/rake folders from

Rails Postgres query, selecting only items that appear in all search params with associations

安稳与你 提交于 2019-12-19 09:24:10
问题 I'm looking to create a Postgres query based on a few user select params. A user will select a shop and a start and end year. Once submitted I'm would only like to display average prices of items if they only exist in all years selected. For example, a user selects a start date of 2014 and end date of 2018. Item banana features in all those years, but apple only features in 2014, 2015 and 2017. So my end result will only show the average price of bananas and not apples. So far, this is the

Remove all data from Active Storage?

可紊 提交于 2019-12-19 07:58:58
问题 I would like to know how can I delete all data from Active Storage or even resetting Active Storage? There is any way to do that? Thank you in advance! NOTE: I'm using Rails 5.2 回答1: This question challenged me, so I did some test on my dummy app with local storage. I have the usual model User which has_one_attached :avatar On local storage files are saved on /storage folder, under subfolders named randomly with a string of two characters. Informations related to files are stored in two

RoR 5.0.0 ActionCable wss WebSocket handshake: Unexpected response code: 301

自闭症网瘾萝莉.ら 提交于 2019-12-19 05:59:17
问题 Hello I'm trying to serve a simple chat using ror 5.0.0 beta (with puma) working on production mode (in localhost there are no problems). This is my Nginx configuration: upstream websocket { server 127.0.0.1:28080; } server { listen 443; server_name mydomain; ssl_certificate ***/server.crt; ssl_certificate_key ***/server.key; ssl on; ssl_session_cache builtin:1000 shared:SSL:10m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4; ssl

Authenticating ActionCable connections

半腔热情 提交于 2019-12-19 03:39:07
问题 I've found a wonderful ActionCable gem, which is a good solution for SPA. I want to send only the html , css and js assets, all other connections will be implemented through ActionCable . It's not difficult to exchange strings or integers, but how can I login through ActionCable? 回答1: From the Readme # app/channels/application_cable/connection.rb module ApplicationCable class Connection < ActionCable::Connection::Base identified_by :current_user def connect self.current_user = find_verified

rails 5 db:reset not working

a 夏天 提交于 2019-12-19 03:06:48
问题 I want to reset the database of my rails 5 project, but the rails db:reset command is not working. errormessage: Permission denied @ unlink_internal - C:/sites5/dawnrebirth/db/development.sqlite3 Couldn't drop database 'db/development.sqlite3' rails aborted! Errno::EACCES: Permission denied @ unlink_internal - C:/sites5/dawnrebirth/db/development.sqlite3 bin/rails:4:in `require' bin/rails:4:in `<main>' Tasks: TOP => db:drop:_unsafe (See full trace by running task with --trace) 回答1: Usually

NGINX configuration for Rails 5 ActionCable with puma

对着背影说爱祢 提交于 2019-12-18 12:18:58
问题 I am using Jelastic for my development environment (not yet in production). My application is running with Unicorn but I discovered websockets with ActionCable and integrated it in my application. Everything is working fine in local, but when deploying to my Jelastic environment (with the default NGINX/Unicorn configuration), I am getting this message in my javascript console and I see nothing in my access log WebSocket connection to 'ws://dev.myapp.com:8080/' failed: WebSocket is closed

Rails 5, Rspec: Environment data not found in the schema

陌路散爱 提交于 2019-12-18 12:04:30
问题 After upgrading a Rails app to Rails 5, running RSpec tests gives me the following error: rails aborted! ActiveRecord::NoEnvironmentInSchemaError: Environment data not found in the schema. To resolve this issue, run: bin/rails db:environment:set RAILS_ENV=test However, that bin does not exist and I can't seem to generate it with bundle binstubs rails or with rake rails:update:bin . I have also tried: rails db:environment:set RAILS_ENV=test rake db:environment:set RAILS_ENV=test There is a