Skip to content

Instantly share code, notes, and snippets.

@komagata
Created August 31, 2008 12:48
Show Gist options
  • Save komagata/8181 to your computer and use it in GitHub Desktop.
Save komagata/8181 to your computer and use it in GitHub Desktop.
module ActiveRecord::ConnectionAdapters::SchemaStatements
def add_foreign_key(from_table, from_column, to_table)
constraint_name = "fk_#{from_table}_#{to_table}"
execute "alter table #{from_table} add constraint \
#{constraint_name} foreign key (#{from_column}) references #{to_table}(id)"
end
def set_auto_increment(table_name, number)
execute "ALTER TABLE #{quote_table_name(table_name)} AUTO_INCREMENT=#{number}"
end
def load_fixture(fixture, dir = "test/fixtures")
require "active_record/fixtures"
Fixtures.create_fixtures(dir, fixture)
end
end
ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.update(
:short_jp => "%m月%d日",
:long_jp => "%Y年%m月%d日"
)
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update(
:short_jp => "%m月%d日 %H時%M分",
:long_jp => "%Y年%m月%d日 %H時%M分"
)
module ApplicationHelper
def web_root
request.protocol+request.host_with_port
end
def free_dial?(str)
/^0120/ =~ str ? true : false
end
def notice
content_tag(:div, image_tag("notice.gif", :class => "icon")+flash[:notice], :id => "notice") if flash[:notice]
end
def warn
content_tag(:div, image_tag("warn.gif", :class => "icon")+flash[:warn], :id => "warn") if flash[:warn]
end
def focus(element)
content_tag(:script, "document.getElementById('#{element}').focus()", :type => "text/javascript")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment