Using fonts with Rails asset pipeline

If your Rails version is between > 3.1.0 and < 4, place your fonts in any of the these folders: app/assets/fonts lib/assets/fonts vendor/assets/fonts For Rails versions > 4, you must place your fonts in the app/assets/fonts folder. Note: To place fonts outside of these designated folders, use the following configuration: config.assets.precompile << /\.(?:svg|eot|woff|ttf)\z/ For Rails … Read more

Add a reference column migration in Rails 4

Rails 4.x When you already have users and uploads tables and wish to add a new relationship between them. All you need to do is: just generate a migration using the following command: rails g migration AddUserToUploads user:references Which will create a migration file as: class AddUserToUploads < ActiveRecord::Migration def change add_reference :uploads, :user, index: … Read more

@ variables in Ruby on Rails

title is a local variable. They only exists within its scope (current block) @title is an instance variable – and is available to all methods within the class. You can read more here: http://strugglingwithruby.blogspot.dk/2010/03/variables.html In Ruby on Rails – declaring your variables in your controller as instance variables (@title) makes them available to your view.

Rails: How to run `rails generate scaffold` when the model already exists?

TL;DR: rails g scaffold_controller <name> Even though you already have a model, you can still generate the necessary controller and migration files by using the rails generate option. If you run rails generate -h you can see all of the options available to you. Rails: controller generator helper integration_test mailer migration model observer performance_test plugin … Read more

How do you delete an ActiveRecord object?

It’s destroy and destroy_all methods, like user.destroy User.find(15).destroy User.destroy(15) User.where(age: 20).destroy_all User.destroy_all(age: 20) Alternatively you can use delete and delete_all which won’t enforce :before_destroy and :after_destroy callbacks or any dependent association options. User.delete_all(condition: ‘value’) will allow you to delete records without a primary key Note: from @hammady’s comment, user.destroy won’t work if User model has … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)