ruby-on-rails-5

How to merge nested attributes in permit + Rails

喜夏-厌秋 提交于 2019-12-23 20:14:17
问题 params.require(:task).permit(:summary, comments_attributes: [:id, :content]) I want to add user_id and project_id in comments_attributes. user_id = current_user.id project_id = project.id I tried with below but not working params.require(:task).permit(:summary, comments_attributes: [:id, :content]).merge(user_id: current_user.id, comments_attributes: [user_id: current_user.id, project_id: project.id]) Please help me how can I do this? 回答1: you will have to use deep_merge params.require(:task)

Getting Message from application: Invalid option key: raise_on_unfiltered_parameters= (RuntimeError) error while running production mode?

*爱你&永不变心* 提交于 2019-12-23 19:22:03
问题 Hi I am trying to run the rails app inside a docker in production mode. it is throwing below error. Message from application: Invalid option key: raise_on_unfiltered_parameters= (RuntimeError) Because of this my application server is not started and i am getting error page. Dockerfile: FROM docker.aws.com:443/consumertech/ruby-nginx-lua-anti-scrape:latest # copy app source RUN mkdir -p /data/app/my-app RUN mkdir -p /data/app/my-app/log RUN mkdir -p /data/app/my-app/tmp RUN touch /data/app/my

Possible to mount multiple ActionCable cables?

人盡茶涼 提交于 2019-12-23 18:20:55
问题 Is it possible to mount multiple ActionCable cables in the same Rails application? For example as such: #routes.rb Rails.application.routes.draw do ... mount ActionCable.server => '/cable' mount ActionCable.server => '/cable2' end I am aware I can have multiple channels using the same cable , but I require to use different authentication methods for my channels. From my understanding, this is not possible using the same cable. Thanks for your help. 回答1: As elaborated in Using ActionCable with

Devise Parameter Sanitizer “For” Method Not Found Rails 5

人盡茶涼 提交于 2019-12-23 17:33:41
问题 I have just added devise to my shiny new Rails 5 app. All's good and dandy until I try to add a username to the Devise user model. Everything worked until I ran it and went to localhost:3000/users/sign_up, where I was greeted by this error: undefined method `for' for #<Devise::ParameterSanitizer:0x007fa0dc31c1b0> Did you mean? fork I have searched the wonderful place of Google for any results, only being given outdated, Rails 4 errors and solutions, the same with searching Stack Overflow

Rails 5 CarrierWave Gem Works in Production But Not In Development

那年仲夏 提交于 2019-12-23 17:02:46
问题 Gem & Ruby Versions ruby '2.5.3', 'rails', '~> 5.2.1', 'carrierwave', '~> 1.2', '>= 1.2.3' When I upload images in my local development environment, I receive no errors and no images are uploaded, but my same application in my production environment uploads images as it should. I've double checked my settings and cannot see anything out of place and the fact that it works in production has me confused. image_uploader.rb class ImageUploader < CarrierWave::Uploader::Base include CarrierWave:

Rails 5 CarrierWave Gem Works in Production But Not In Development

 ̄綄美尐妖づ 提交于 2019-12-23 16:57:24
问题 Gem & Ruby Versions ruby '2.5.3', 'rails', '~> 5.2.1', 'carrierwave', '~> 1.2', '>= 1.2.3' When I upload images in my local development environment, I receive no errors and no images are uploaded, but my same application in my production environment uploads images as it should. I've double checked my settings and cannot see anything out of place and the fact that it works in production has me confused. image_uploader.rb class ImageUploader < CarrierWave::Uploader::Base include CarrierWave:

Using Bootstrap gem with Rails

荒凉一梦 提交于 2019-12-23 15:19:42
问题 I have a fresh rails project where I only generated a controller. I've followed the directions to install bootstrap according to the bootstrap gem, and I keep getting the following error: ActionView::Template::Error (identifier '(function(opts, pluginOpts) {return eva l(process' undefined): 5: <%= csrf_meta_tags %> 6: <%= csp_meta_tag %> 7: 8: <%= stylesheet_link_tag 'application', media: 'all', 'data-turbol inks-track': 'reload' %> 9: <%= javascript_include_tag 'application', 'data

Rails 5.2 and Active Record migration with CURRENT_TIMESTAMP

霸气de小男生 提交于 2019-12-23 14:56:59
问题 I have some attributes that need to have default values. I've set up my migrations to set the defaults in the database as follows: class AddDefaultsToModel < ActiveRecord::Migration[5.2] def change change_column :posts, :post_type, :string, default: 'draft' change_column :posts, :date_time, :datetime, default: -> { 'CURRENT_TIMESTAMP' } end end The defaults work great when adding directly to the database. However, if I build a new model in Rails, one attribute works as expected, the other

Routing for sessions#destroy action

泪湿孤枕 提交于 2019-12-23 12:17:58
问题 I'm linking to the destroy action for the Sessions controller like this: <%= link_to "Sign out", session_path, method: :delete %> Routes.rb: resources :sessions, only: [:new, :create, :destroy] Rails complains about the link above: No route matches {:action=>"destroy", :controller=>"sessions"} missing required keys: [:id] How do I link to the destroy action and keeping the REST/resource methodology in Rails when there's no object ID to provide for the link? 回答1: It is best to treat the routes

How to set params when subscribing to Action Cable channel

拟墨画扇 提交于 2019-12-23 09:47:51
问题 I've been trying to get my head around action cable for what seems like months. Please help. I have a "Connection" - I can't set the identified_by :current_user because this endpoint also needs to be consumed by an external API that uses WebSockets. Can't use browser cookies to authenticate the API endpoint. Files & Support Connection: /app/channels/application_cable/connection.rb module ApplicationCable class Connection < ActionCable::Connection::Base end end Channel: /app/channels