Rails naming convention for join table

categories_products. Both plural. In lexical order. Quote: Unless the name of the join table is explicitly specified by using the :join_table option, Active Record creates the name by using the lexical order of the class names. So a join between customer and order models will give the default join table name of “customers_orders” because “c” … Read more

Slow initial server startup when using Phusion Passenger and Rails

What’s happening is that your Application and/or ApplicationSpawners are shutting down due to time-out. To process your new request, Passenger has to startup a new copy of your application, which can take several seconds, even on a fast machine. To fix the issue, there are a few Apache configuration options you can use to keep … Read more

Rails – Validate Presence Of Association?

You can use validates_presence_of http://apidock.com/rails/ActiveModel/Validations/ClassMethods/validates_presence_of class A < ActiveRecord::Base has_many :bs validates_presence_of :bs end or just validates http://apidock.com/rails/ActiveModel/Validations/ClassMethods/validates class A < ActiveRecord::Base has_many :bs validates :bs, :presence => true end But there is a bug with it if you will use accepts_nested_attributes_for with :allow_destroy => true: Nested models and parent validation. In this topic you … Read more

Rails: How to change the title of a page?

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