Questions tagged [ruby-on-rails-4]

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

Ruby on Rails 4.0, "an open-source web framework that's optimized for programmer happiness and sustainable productivity." Rails 4.0 brings a bunch of new features and improvements over older Rails versions.

See Ruby on Rails 4.0 Release Notes for more information.

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

Resources

Related tags

36770 questions
36
votes
2 answers

Cannot start rails 4 console on production server

Having a weird issue and need help. I am trying to start a rails console on a production server and it is acting like the rails c command does not exist. FWIW, I have been a rails developer for 4 years and do this all the time on a plethora of other…
johndavid400
  • 1,552
  • 13
  • 15
36
votes
20 answers

Bootstrap 3+Rails 4 - Certain Glyphicons not working

I am trying to use bootstrap 3 in my rails 4 app. Followed this tutorial to set up bootstrap 3 using bootstrap saas from this github page. Bootstrap is working fine but glyphicons are not working as expected. Certain glyphicons are not displaying at…
36
votes
4 answers

Create if record does not exist

I have 3 models in my rails app class Contact < ActiveRecord::Base belongs_to :survey, counter_cache: :contact_count belongs_to :voter has_many :contact_attempts end class Survey < ActiveRecord::Base has_many :questions has_many…
gsueagle2008
  • 4,583
  • 10
  • 36
  • 46
36
votes
4 answers

Invalid single-table inheritance type: Rails

I'm getting this error when trying to create a new Product in my Rails application. Invalid single-table inheritance type: Movie is not a subclass of Product How can I resolve this? controller class ProductsController < ApplicationController …
Antarr Byrd
  • 24,863
  • 33
  • 100
  • 188
36
votes
6 answers

strong parameters permit all attributes for nested attributes

Is there a way in strong parameters to permit all attributes of a nested_attributes model? Here is a sample code. class Lever < ActiveRecord::Base has_one :lever_benefit accepts_nested_attributes_for :lever_benefit end class LeverBenefit <…
36
votes
8 answers

Can't get CSS working on Heroku using Rails 4 with bootstrap-sass gem

I have deployed an app to Heroku with one issue I can't seem to get figured out. The CSS for the app via Bootstrap-sass does not load up thus I have an un-styled app. At the moment this is just a collection of static pages. I have followed all but…
Kevin Dark
  • 2,139
  • 5
  • 22
  • 23
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
6 answers

Rails 4: Add Multiple Columns to Existing Table

I know how to add one column to an existing table. Now I have to add many columns to an existing table. Is there a shorter way for: add_col1_col2_col3_col4_.._coln_to_tables col1:integer col2:integer etc... Do I have to do the above for ALL the…
Sylar
  • 11,422
  • 25
  • 93
  • 166
35
votes
4 answers

Missing production secret_key_base in rails

I have recently deployed an app and got an internal server error because of missing production secret_key_base. After hours of testing, I managed to solve this problem with two methods: Method 1: I generated a new secret_key with rake secret and…
user3631047
  • 3,256
  • 5
  • 23
  • 34
35
votes
7 answers

Redis + ActionController::Live threads not dying

Background: We've built a chat feature in to one of our existing Rails applications. We're using the new ActionController::Live module and running Puma (with Nginx in production), and subscribing to messages through Redis. We're using EventSource…
35
votes
3 answers

How to use Rails 4 strong parameters with has_many :through association?

I'm having trouble getting a has_many :through association working with Rails 4's strong parameters. I have a model called Checkout and I need to select a person from the Employee model in the new checkout form. Checkouts and Employees are…
Lee McAlilly
  • 9,084
  • 12
  • 60
  • 94
35
votes
11 answers

Ruby on Rails - "Add 'gem sqlite3'' to your Gemfile"

I was following the Rails tutorial, but I got stuck when it said to type rails server in the blog directory. It states Specified 'sqlite3' for database adapter, but the gem is not loaded. Add gem 'sqlite3' to your Gemfile. I quit the server,…
hewhocomes
  • 441
  • 1
  • 4
  • 9
35
votes
6 answers

Rails 4.0 Strong Parameters nested attributes with a key that points to a hash

I was playing around with Rails 4.x beta and trying to get nested attributes working with carrierwave. Not sure if what I'm doing is the right direction. After searching around, and then eventually looking at the rails source and strong parameters…
John
  • 495
  • 1
  • 4
  • 8
34
votes
2 answers

Option for Cascade Delete for References or On Delete

In Rails 4.2, when creating a table or adding a reference via references or add_reference how do you specify that the foreign key should cascade on delete. Command to generate scaffold: rails g scaffold Child parent:references name:string Resulting…
WiredIn
  • 4,157
  • 4
  • 27
  • 23
34
votes
1 answer

Difference between add_dependency and add_runtime_dependency?

What is the difference between using add_dependency and add_runtime_dependency in a Rails engine's gemspec? For example: Gem::Specification.new do |s| s.add_dependency 'jquery-rails' s.add_runtime_dependency 'jquery-rails' end What's the…
Jacob
  • 6,317
  • 10
  • 40
  • 58