Rails – controller action name to string
Rails 2.X: @controller.action_name Rails 3.1.X: controller.action_name, action_name Rails 4.X: action_name
Rails 2.X: @controller.action_name Rails 3.1.X: controller.action_name, action_name Rails 4.X: action_name
You can also delegate: class Company < ActiveRecord::Base has_many :employees has_many :dogs, :through => :employees end class Employee < ActiveRescord::Base belongs_to :company has_many :dogs end class Dog < ActiveRecord::Base belongs_to :employee delegate :company, :to => :employee, :allow_nil => true end
If the URL is using https instead of http, you need to add the following line: parsed_url = URI.parse(url) http = Net::HTTP.new(parsed_url.host, parsed_url.port) http.use_ssl = true Note the additional http.use_ssl = true. And the more appropriate code which would handle both http and https will be similar to the following one. url = URI.parse(domain) req … Read more
rake routes or bundle exec rake routes
If you are looking for only attributes, then you can get them by: @post.attributes Note that this calls ActiveModel::AttributeSet.to_hash every time you invoke it, so if you need to access the hash multiple times you should cache it in a local variable: attribs = @post.attributes
In your views do something like this: <% content_for :title, “Title for specific page” %> <!– or –> <h1><%= content_for(:title, “Title for specific page”) %></h1> The following goes in the layout file: <head> <title><%= yield(:title) %></title> <!– Additional header tags here –> </head> <body> <!– If all pages contain a headline tag, it’s preferable to … Read more
Restarting Spring should fix the hanging commands: $ bin/spring stop I experienced hanging commands (rake, bin/rails, etc.) after deleting and recreating a new Ruby on Rails application. Google wasn’t that helpful. I hope this is. Spring will start automatically when you re-run your command.
Postgres has two different timestamp data types: timestamp with time zone, short name: timestamptz timestamp without time zone, short name: timestamp timestamptz is the preferred type in the date/time family, literally. It has typispreferred set in pg_type, which can be relevant: Generating time series between two dates in PostgreSQL Internal storage and epoch Internally, timestamps … Read more
There are a couple differences, but they’re not big: .create is equivalent to .new followed by .save. It’s just more succinct. .create! is equivalent to .new followed by .save! (throws an error if saving fails). It’s also just a wee bit shorter I think .build is mostly an alias for .new. It works one way … Read more
This parameter was added to forms in order to force Internet Explorer (5, 6, 7 and 8) to encode its parameters as unicode. Specifically, this bug can be triggered if the user switches the browser’s encoding to Latin-1. To understand why a user would decide to do something seemingly so crazy, check out this google … Read more