Ruby on Rails generates model field:type – what are the options for field:type?
:primary_key, :string, :text, :integer, :float, :decimal, :datetime, :timestamp, :time, :date, :binary, :boolean, :references See the table definitions section.
:primary_key, :string, :text, :integer, :float, :decimal, :datetime, :timestamp, :time, :date, :binary, :boolean, :references See the table definitions section.
Asked the same question to one of Rails-Core’s members: https://twitter.com/luislavena/status/108998968859566080 And the answer: https://twitter.com/tenderlove/status/108999110136303617 ya, it’s fine. Need to clean it up, but nothing is being hurt.
These answers are a bit dated. Therefore I give you: hash = JSON.parse string Rails should automagically load the json module for you, so you don’t need to add require ‘json’.
In Rails 3 and newer: Rails.root which returns a Pathname object. If you want a string you have to add .to_s. If you want another path in your Rails app, you can use join like this: Rails.root.join(‘app’, ‘assets’, ‘images’, ‘logo.png’) In Rails 2 you can use the RAILS_ROOT constant, which is a string.
It could be as simple as a stale PID file. It could be failing silently because your computer didn’t complete the shutdown process completely which means postgres didn’t delete the PID (process id) file. The PID file is used by postgres to make sure only one instance of the server is running at a time. … Read more
You can show them with rake routes directly. In a Rails console, you can call app.post_path. This will work in Rails ~= 2.3 and >= 3.1.0.
You’ll probably want to use a DECIMAL type in your database. In your migration, do something like this: # precision is the total number of digits # scale is the number of digits to the right of the decimal point add_column :items, :price, :decimal, :precision => 8, :scale => 2 In Rails, the :decimal type … Read more
This is really late, but here’s how you can find where a method is defined: http://gist.github.com/76951 # How to find out where a method comes from. # Learned this from Dave Thomas while teaching Advanced Ruby Studio # Makes the case for separating method definitions into # modules, especially when enhancing built-in classes. module Perpetrator … Read more
In Rails 3, Application specific custom configuration data can be placed in the application configuration object. The configuration can be assigned in the initialization files or the environment files — say for a given application MyApp: MyApp::Application.config.custom_config_variable = :my_config_setting or Rails.configuration.custom_config_variable = :my_config_setting To read the setting, simply call the configuration variable without setting it: … Read more
As we can see in ActionController::Base, before_action is just a new syntax for before_filter. However the before_filter syntax is deprecated in Rails 5.0 and will be removed in Rails 5.1