Rails: How to reference images in CSS within Rails 4

Sprockets together with Sass has some nifty helpers you can use to get the job done. Sprockets will only process these helpers if your stylesheet file extensions are either .css.scss or .css.sass. Image specific helper: background-image: image-url(“logo.png”) Agnostic helper: background-image: asset-url(“logo.png”, image) background-image: asset-url($asset, $asset-type) Or if you want to embed the image data in … Read more

Rails 4 turbo-link prevents jQuery scripts from working

$(document).ready(function(){ doesn’t really work with Turbolinks. Turbolinks: … makes following links in your web application faster. Instead of letting the browser recompile the JavaScript and CSS between each page change, it keeps the current page instance alive and replaces only the body and the title in the head. So the page is only loaded once … Read more

How to use ANY instead of IN in a WHERE clause?

There are two variants of IN expressions: expression IN (subquery) expression IN (value [, …]) Similarly, two variants with the ANY construct: expression operator ANY (subquery) expression operator ANY (array expression) A subquery works for either technique, but for the second form of each, IN expects a list of values (as defined in standard SQL) … Read more

Nested attributes unpermitted parameters

Seems there is a change in handling of attribute protection and now you must whitelist params in the controller (instead of attr_accessible in the model) because the former optional gem strong_parameters became part of the Rails Core. This should look something like this: class PeopleController < ActionController::Base def create Person.create(person_params) end private def person_params params.require(:person).permit(:name, … Read more

Rails 4 multiple image or file upload using carrierwave

This is solution to upload multiple images using carrierwave in rails 4 from scratch Or you can find working demo : Multiple Attachment Rails 4 To do just follow these steps. rails new multiple_image_upload_carrierwave In gem file gem ‘carrierwave’ bundle install rails generate uploader Avatar Create post scaffold rails generate scaffold post title:string Create post_attachment … Read more

Auto-loading lib files in Rails 4

I think this may solve your problem: in config/application.rb: config.autoload_paths << Rails.root.join(‘lib’) and keep the right naming convention in lib. in lib/foo.rb: class Foo end in lib/foo/bar.rb: class Foo::Bar end if you really wanna do some monkey patches in file like lib/extensions.rb, you may manually require it: in config/initializers/require.rb: require “#{Rails.root}/lib/extensions” P.S. Rails 3 Autoload … Read more

How is attr_accessible used in Rails 4?

Rails 4 now uses strong parameters. Protecting attributes is now done in the controller. This is an example: class PeopleController < ApplicationController def create Person.create(person_params) end private def person_params params.require(:person).permit(:name, :age) end end No need to set attr_accessible in the model anymore. Dealing with accepts_nested_attributes_for In order to use accepts_nested_attribute_for with strong parameters, you will … Read more