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
71
votes
6 answers

has_many, belongs_to relation in active record migration rails 4

I have a User model and a Task model. I have not mentioned any relation between them while creating them. I need to establish that User has_many Tasks and a Task belongs_to User through a migration What would be the migration generation command…
71
votes
6 answers

Does Rails 4 have support for OR queries

So in Rails 4 the long desired feature to use not queries has been added. Article.where.not(title: 'Rails 3') Has similar support been added for or queries, or are they planning to make it. I couldn't find anything by browsing through the release…
Arjan
  • 6,264
  • 2
  • 26
  • 42
70
votes
7 answers

Why am I asked to run 'rake db:migrate RAILS_ENV=test'?

On Rails 4.0.0.rc1, Ruby 2.0.0, after I run a migration, I see the following error when I try to run a test through rspec: /Users/peeja/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0.rc1/lib/active_record/migration.rb:376:in …
Peeja
  • 13,683
  • 11
  • 58
  • 77
69
votes
2 answers

RoR nested attributes produces duplicates when edit

I'm trying to follow Ryan Bates RailsCast #196: Nested model form part 1. There're two apparent differences to Ryans version: 1) I'm using built-in scaffolding and not nifty as he's using, and 2) I'm running rails 4 (I don't really know what version…
conciliator
  • 6,078
  • 6
  • 41
  • 66
67
votes
8 answers

ActionController::InvalidAuthenticityToken in RegistrationsController#create

Hi I am using Devise for my user authentication suddenly my new user registration was not working. this was error I am getting. ActionController::InvalidAuthenticityToken Rails.root: /home/example/app Application Trace | Framework Trace | Full…
user3144005
  • 839
  • 1
  • 8
  • 13
65
votes
7 answers

rails console doesn't start

I`m in root of my application, and when I type $ rails console It looks like something is loading, but nothing happens. And when I stop ^C I received this trace: ^C/home/jonatas/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/run.rb:54:in…
JonatasTeixeira
  • 1,474
  • 1
  • 18
  • 24
65
votes
8 answers

How to use fonts in Rails 4

I have a Rails 4 application and I am trying to use a custom font. I have followed many tutorials on this and somehow it's just not working for my application. I am using application.css.less and have the following declaration: @font-face { …
SnareChops
  • 13,175
  • 9
  • 69
  • 91
64
votes
4 answers

Postgres JSON data type Rails query

I am using Postgres' json data type but want to do a query/ordering with data that is nested within the json. I want to order or query with .where on the json data type. For example, I want to query for users that have a follower count > 500 or I…
Mohamed El Mahallawy
  • 13,024
  • 13
  • 52
  • 84
64
votes
6 answers

Default value for input with simple_form

im trying to do default value for input works ok: <%= f.input_field :quantity, default: '1' %> but i need f.input not f.input_field <%= f.input :quantity %> im trying it with standard html value - but after unsucessfull validation quantity is…
patie
  • 1,074
  • 1
  • 10
  • 18
62
votes
3 answers

PG::UndefinedTable: ERROR: missing FROM-clause entry for table when using joins and where

I have two models, Courier and Order. I have the following query below: active_couriers = Courier. available_courier_status. where(:service_region_id => @service_region.id). includes(:orders) This query works, however, it pulls in all…
Huy
  • 10,806
  • 13
  • 55
  • 99
62
votes
5 answers

Why is it best to store a telephone number as a string vs. integer?

As the question states, why is it considered best practice to store telephone numbers as strings rather than integers in the telephone_number column? Not sure I understand the rationale for this. Please help clear this up! Thanks!
user3399101
  • 1,477
  • 3
  • 14
  • 29
62
votes
5 answers

How to Create a New Table With a Unique Index in an Active Record / Rails 4 Migration

How do I create a new table, through a rails migration, and add an unique index to it? In the docs I found how to add a index to a table after it's been created, but how do you do both -- create the table, and add the unique index -- in the same…
newUserNameHere
  • 17,348
  • 18
  • 49
  • 79
62
votes
11 answers

How to rename rails 4 app?

rails plugin install git://github.com/get/Rename.git will allow us to rename only rails 3 app Is there any gem available to rename Rails 4 app. If not, suggest me the better way to rename.
Arun Kumar Kandasamy
  • 1,016
  • 2
  • 12
  • 24
62
votes
6 answers

Rails 4 Unpermitted Parameters for Array

I have an array field in my model and I'm attempting to update it. My strong parameter method is below def post_params params["post"]["categories"] = params["post"]["categories"].split(",") params.require(:post).permit(:name, :email,…
thank_you
  • 11,001
  • 19
  • 101
  • 185
62
votes
3 answers

rails 4 asset pipeline vendor assets images are not being precompiled

I'm using rails 4 & ruby 1.9.3 for my application and fancybox2-rails gem, but there's a general problem with asset pipeline. If I run rake task for precompile, then everything is fine except for images in vendor/assets/images and…
banesto
  • 1,672
  • 1
  • 13
  • 13