Problem
When using cap deploy_with_migrations, the default behaviour is to deploy with the migrations in the production environment.
Solution
To change this behavior add:
set :rails_env, "development"
in your config/deploy.rb
Problem
When using cap deploy_with_migrations, the default behaviour is to deploy with the migrations in the production environment.
Solution
To change this behavior add:
set :rails_env, "development"
in your config/deploy.rb
Problem
You are using file_column plugin (or maybe another plugin?), to upload files in your ruby on rails application. Because the files are big you don’t want to have a different copy stored in your subversion repository for each different deployment version. You want to keep a common folder with all your uploaded files, and use it with every different deployment version.
Solution
For the example, we will have a numbers table that has two file_column uploadable columns (intro,voice_mail), with the following migration:
class CreateNumbers < ActiveRecord::Migration def self.up create_table :numbers do |t| t.column :customer_id, :int, :null => false t.column :phone_no, :string, :null => false t.column :intro, :string t.column :vmail, :string t.column :created_at, :datetime t.column :updated_at, :datetime end def self.down drop_table :numbers end end
Capistrano.configuration(:must_exist).load do desc "Keep generated uploaded files between deployments" task :after_symlink do run "rm -drf #{deploy_to}/#{current_dir}/public/number" sudo "ln -nfs #{shared_path}/number #{deploy_to}/#{current_dir}/public" end end
Be careful with the naming of the task as (at least for capistrano 1.4 that I’m using), it must have a special name as after_symlink.
Also be careful that if you try to use before_symlink, it won’t work as the current symlink won’t be setup.
require 'lib/cap_recipes'
svn -m "added customised capistrano recipes" commit
make sure that you check in your version in subversion, and then:
cap deploy
you should be able to see a link in your current/public folder called number that points to the shared/number folder that hold all the uploaded files.
Problem
You want to replace the standard text descriptions in ActiveScaffold’s actions with your icons.
Solution
/* Table :: Actions (Edit,Delete) .... */
and for each action that you want to use an icon add (ie edit)
.active_scaffold tr.record td.actions a.edit { display: block; width: 16px; height: 16px; background: transparent url(../../../images/active_scaffold/my_images/image.png) no-repeat right 50%; }
ActiveScaffold.set_defaults do |config| config.update.link.label ="" end
<%= stylesheet_link_tag "active_scaffold_overrides" %>
Problem
You need to have to functionally test your controller when you are using ActiveScaffold. There are pieces of code that tell you how to do that on a normal ror application (ie without ActiveScaffold), like recipe 7.17 on the Rails Cookbook, or a fragment of code in an Active Scaffold application, but they don’t have the full details.
Solution
Here is an attempt to give some more detailed step by step instructions on how to do it.
class CreateCustomers < ActiveRecord::Migration def self.up # Create customers table create_table :customers do |t| t.column :customer_code, :string, :null => false t.column :created_at, :datetime t.column :updated_at, :datetime end end end
class Customer < ActiveRecord::Base has_many :numbers def to_label "#{customer_code}" end end
class CustomersController < ApplicationController active_scaffold :customer do |config| config.list.columns = [:customer_code, :numbers, :created_at, :updated_at] config.columns[:customer_code].inplace_edit = true end end
first_customer: id: 1 customer_code: 123 created_at: 2007-09-26 11:17:07 updated_at: 2007-09-26 11:17:07 second_customer: id: 2 customer_code: 456 created_at: 2007-09-26 11:17:13 updated_at: 2007-09-26 11:17:13
require File.dirname(__FILE__) + '/../test_helper' require 'customers_controller' class CustomerControllerTest < Test::Unit::TestCase fixtures :customers def setup @controller = CustomersController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new end def test_index get :index assert_response :success assert_template 'list' end def test_new get :new assert_response :success assert_template 'create_form' end def test_edit get :edit, :id => customers(:first_customer).id assert_response :success assert_template 'update_form' end def test_show get :show, :id => customers(:first_customer).id assert_response :success assert_template 'show' end def test_customer_controller_CRUD # CREATE # Get the number of records record_no = Customer.count # Create a new record post :create, {"commit"=>"Create", :record=>{"customer_code"=>"890"}} # Assert that the record is not nil assert_not_nil assigns("record") # Look that the number of records has been increased by 1 assert_equal record_no+1, Customer.count # UPDATE # Get the number of records record_no = Customer.count # Update a record new_customer_code = "987" put :update, {"commit"=>"Update",:id=>customers(:first_customer).id, :record=>{"customer_code"=>new_customer_code}} # Assert that the record is not nil assert_not_nil assigns("record") # Look that the number of records has stayed the same assert_equal record_no, Customer.count # Check that the update took place customer = Customer.find(customers(:first_customer).id) assert_equal new_customer_code, customer.customer_code # DELETE # Get the number of records record_no = Customer.count # Delete a record delete :destroy, :id => customers(:first_customer).id # Look that the number of records has been decreased by 1 assert_equal record_no-1, Customer.count end end
After spending some time trying to make a migration work, and having the error message coming back:
You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.[]
I’ve decided to do a google search for the specific problem, as it was working fine with other test migrations.
It turns out that if the migration is not model specific, but a different one (ie trying to add a new column to an existing table), the :int for the column doesn’t work!
It has to be :integer.
Full bug report and the article are here:
Migrations: :integer works, :int doesn’t – datatype discrepancy
To control the date format in dhtmlcalendar within ActiveScaffold in Ruby on Rails, to make the date of 2 November 2007 appear like 02-11-2007, use:
i) if you want to affect the settings in all the application add the following to the top of your controllers/application.rb
ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMAT[:default] = ‘%d-%m-%Y’
ii) If you only want to affect the settings of the calendar in one specific controller, then add the same line only to the controller that you want:
ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMAT[:default] = '%d-%m-%Y'