昔は草花を育てるのは、まどろっこしくあんまり好きでなかったのです。
水をあげたら、すぐ育つぐらいのレスポンスを求めていたのかもしれないです。
最近は子育てしているせいか、レスポンスがなくても全然平気です。
昨日との違いはなくても、長い目で見れば着実に育っている感じが
子育てと通じるものがあるので、ちょっと草花を育てるのも楽しいのかもしれません。
そんな草花を育てるのをより楽しむために、以下の本を買ってみたりしてみました。
def file_column(attr, options={})
options = DEFAULT_OPTIONS.merge(options) if options
my_options = FileColumn::init_options(options,
# Inflector.underscore(self.name).to_s,
ActiveSupport::Inflector.underscore(self.name).to_s,
attr.to_s)
state_attr = "@#{attr}_state".to_sym
state_method = "#{attr}_state".to_sym
これとは別に以下のサイトでも直し方が紹介されています。def self.sanitize_filename(filename)
filename = File.basename(filename.gsub("\\", "/")) # work-around for IE
# filename.gsub!(/[^a-zA-Z0-9\.\-\+_]/,"_")
filename.gsub!(/[^\w\.\-\+_]/,"_")
filename = "_#{filename}" if filename =~ /^\.+$/
filename = "unnamed" if filename.size == 0
filename
end
以下のサイトを参考にさせていただきました。class Foo < ActiveRecord::Base
file_column :filename, :web_root => "upload/",
:root_path => File.join(RAILS_ROOT, "public", "upload")
end
def active_scaffold_column_download_link(column, record, label =
nil)
return nil if record.send(column.name).nil?
label||=as_(:download)
- link_to( label, url_for_file_column(record, column.name.to_s), :popup => true)
+ link_to( label, url_for_file_column(record, column.name.to_s, {:absolute => true}), :popup => true)
end
def active_scaffold_column_thumbnail(column, record)
return nil unless relative_path
url = ""
- url << request.relative_url_root.to_s if absolute
+ url << ActionController::Base.relative_url_root.to_s if absolute
url << "/"
url << object.send("#{method}_options")[:base_url] << "/"
url << relative_path
url = ""
- url << request.relative_url_root.to_s if absolute
- url << "/"
+ url << root_url
url << object.send("#{method}_options")[:base_url] << "/"
url << relative_path
require 'uri'
def url2link_of_string(html_string,options={})
target=options[:target] || '_blank'
URI.extract(html_string).uniq.each{|url|
html_string.gsub!(url,"#{url}")
}
html_string
end
a = Foo.find(:first) => #<Foo id: 1, article: "aaa", created_at: "2011-06-10 17:02:21",updated_at: "2011-06-10 17:02:21"> b = a.clone => #<Foo id: nil, article: "aaa", created_at: "2011-06-10 17:02:21",updated_at: "2011-06-10 17:02:21"> b.created_at = nil => nil b.updated_at = nil => nil b.save! => true p b #<Foo id: 2, article: "aaa", created_at: "2011-06-13 14:27:23", updated_at: "2011-06-13 14:27:23">
def do_destroy
destroy_find_record
begin
self.successful = @record.destroy
rescue Exception => ex
flash[:warning] = "オリジナルメッセージ"
self.successful = false
end
end