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

Rails: How to use i18n with Rails 4 enums

Starting from Rails 5, all models will inherit from ApplicationRecord. class User < ApplicationRecord enum status: [:active, :pending, :archived] end I use this superclass to implement a generic solution for translating enums: class ApplicationRecord < ActiveRecord::Base self.abstract_class = true def self.human_enum_name(enum_name, enum_value) I18n.t(“activerecord.attributes.#{model_name.i18n_key}.#{enum_name.to_s.pluralize}.#{enum_value}”) end end Then I add the translations in my .yml file: en: … Read more

What is `params.require(:person).permit(:name, :age)` doing in Rails 4?

The params in a controller looks like a Hash, but it’s actually an instance of ActionController::Parameters, which provides several methods such as require and permit. The require method ensures that a specific parameter is present, and if it’s not provided, the require method throws an error. It returns an instance of ActionController::Parameters for the key … Read more

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