Rails new vs create

Within Rails’ implementation of REST new and create are treated differently. An HTTP GET to /resources/new is intended to render a form suitable for creating a new resource, which it does by calling the new action within the controller, which creates a new unsaved record and renders the form. An HTTP POST to /resources takes … Read more

How to pass arguments into a Rake task with environment in Rails? [duplicate]

Just to follow up on this old topic; here’s what I think a current Rakefile (since a long ago) should do there. It’s an upgraded and bugfixed version of the current winning answer (hgimenez): desc “Testing environment and variables” task :hello, [:message] => :environment do |t, args| args.with_defaults(:message => “Thanks for logging on”) puts “Hello … Read more

What do helper and helper_method do?

The method helper_method is to explicitly share some methods defined in the controller to make them available for the view. This is used for any method that you need to access from both controllers and helpers/views (standard helper methods are not available in controllers). e.g. common use case: #application_controller.rb def current_user @current_user ||= User.find_by_id!(session[:user_id]) end … Read more

Rails: Missing host to link to! Please provide :host parameter or set default_url_options[:host]

You need to add the following line at every environment: config.action_mailer.default_url_options = { :host => “yourhost” } That way, it can work in all environments and could be different from environment to environment. For example: development.rb config.action_mailer.default_url_options = { :host => “dev.yourhost.com” } test.rb config.action_mailer.default_url_options = { :host => “test.yourhost.com” } production.rb config.action_mailer.default_url_options = { … Read more