Questions tagged [ruby-on-rails-5]

For issues specific to version 5.x.y of Rails. If your question applies to Ruby on Rails in general, use the tag [ruby-on-rails].

Ruby on Rails 5 is the previous major revision of Ruby on Rails, "an open-source web framework that's optimized for programmer happiness and sustainable productivity."

Multiple sub-versions have been released, namely 5.1 and 5.2. Questions regarding specific sub-versions of Ruby on Rails 5 can also be asked on the appropriate tags:

Resources:

See also:

9415 questions
39
votes
1 answer

ActionCable.server.broadcast from the console

I can use the following code in the controller but not in the console (both development environment). I'm using Rails 5.0.0.beta2. ActionCable.server.broadcast 'example_channel', message: '

Test

' The console: >> ActionCable.server.broadcast…
wintermeyer
  • 8,178
  • 8
  • 39
  • 85
38
votes
5 answers

Rails: How to implement protect_from_forgery in Rails API mode

I have a Rails 5 API app (ApplicationController < ActionController::API). The need came up to add a simple GUI form for one endpoint of this API. Initially, I was getting ActionView::Template::Error undefined method protect_against_forgery? when I…
lostphilosopher
  • 4,361
  • 4
  • 28
  • 39
38
votes
2 answers

Change the default value for table column with migration

I try to change the default column value from false to true. But when I run rake db:migrate VERSION=904984092840298 I got the following ERROR. StandardError: An error has occurred, this and all later migrations…
38
votes
2 answers

Rails: Unpermitted parameter in Rails 5

First of all I want simply get an object inside the current object that I'm sending to my backend. I have this simple JSON (generated from a form): { "name": "Project 1", "project_criteria": [ { "name": "Criterium 1", "type":…
developer033
  • 24,267
  • 8
  • 82
  • 108
37
votes
3 answers

How to use params.fetch strong parameters

When using rails g scaffold kittens the strong parameters function, kitten_params is def kitten_params params.fetch(:kitten, {}) end I am familiar with strong parameters, params.require(:kitten).permit(:name, :age) but I'm not sure how to use…
Andy
  • 720
  • 1
  • 7
  • 13
36
votes
1 answer

How to disable coffeescript on Rails 5

I started a new rails 5.1.4 project but I have forgotten to add --skip-coffee on rails new. Is there a way to remove the coffeescript dependency without creating a new project?.
JuanCrg90
  • 1,006
  • 13
  • 24
36
votes
1 answer

Add a reference column migration in Rails 5

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…
kkurian
  • 3,844
  • 3
  • 30
  • 49
35
votes
5 answers

Rails - Validation :if one condition is true

On Rails 5. I have an Order model with a description attribute. I only want to validate it's presence if one of two conditions is met: if the current step is equal to the first step OR if require_validation is equal to true. I can easily validate…
Kathan
  • 1,428
  • 2
  • 15
  • 31
35
votes
3 answers

Rails 5: Array values in the parameter to `Gem.paths=` are deprecated

Building websockets app based off of actioncable-examples. When starting server, running rake, etc. I keep getting the message: Array values in the parameter to `Gem.paths=` are deprecated. Haven't seen a solution here, but did find one. I…
Richard_G
  • 4,700
  • 3
  • 42
  • 78
34
votes
7 answers

How to get url of Active Storage image

I want to get list of records with attached images as a links or files by api. I have a simple model: class Category < ApplicationRecord has_one_attached :image validates :name, presence: true, uniqueness: true end And next action: def index …
zishe
  • 10,665
  • 12
  • 64
  • 103
34
votes
5 answers

Rails 5 db migration: how to fix ActiveRecord::ConcurrentMigrationError

A previous rake db:rollback stalled. Now when attempting a new migration we get the following error: rake aborted! ActiveRecord::ConcurrentMigrationError: Cannot run migrations because another migration process is currently…
KeithP
  • 1,803
  • 1
  • 16
  • 23
32
votes
5 answers

ActiveRecord::NoEnvironmentInSchemaError

I'm trying to perform database related operations on my newly upgraded app(Rails 5) and I'm unable to perform destructive database commands locally. rails db:reset or rails db:drop . The trace results with the following data, rails db:drop…
Coding active
  • 1,620
  • 3
  • 23
  • 40
32
votes
5 answers

verify_authenticity_token has not been defined

Ruby version 2.2.4, Rails version 5.0.0.1. I'm getting stuck at a part of a tutorial where you test login with curl. I get an error ArgumentError (Before process_action callback: verify_authenticity_token has not been defined). I used this code in…
Peter
  • 719
  • 1
  • 8
  • 19
31
votes
0 answers

Using JQuery Server side datatables in ruby app and pagination shows blank page after 1st page

I am using Jquery Server side datatables and am not able to get the pagination to work on pages 2+. I have 200 records. The first page shows 50. When I click the pagination numbers at the bottom of the page it navigates to page 2, but page 2 is…
NothingToSeeHere
  • 2,253
  • 5
  • 25
  • 57
31
votes
2 answers

Is the 'Travel' time helper not available in feature specs?

I just tried to use Rails' time helper method travel in one of my feature specs: scenario 'published_at allows to set a publishing date in the future' do magazine_article.update_attribute(:published_at, Time.now + 1.day) expect { visit…
Flip
  • 6,233
  • 7
  • 46
  • 75