pry(main)> include Rails.application.routes.url_helpers
pry(main)> admin_customer_path(User.first)
User Load (0.3ms) SELECT `users`.* FROM `users` ORDER BY `users`.`id` ASC LIMIT 1
=> "/admin/customers/1"
If you use ActiveRecord::Base.transaction syntax, you shoud surround it begin rescue clauses.
Detail
12345678910111213
class Hoge
def self.exec
raise "something is not good" if something_check
ActiveRecord::Base.transaction do
User.create(username:"moge")
User.create(username:"moge")
end
rescue StandardError => e
# if database transaction has occured, this statements will be called
p "duplicate error"
end
This code looks good, but includes terrible problem.
It’s definetly rescue clause. In this code, something_check return true, raise “something is not good” error, and shows "duplicate error". Terrible.
so if you use ActiveRecord::Base, I strongly recommend use begin rescue clauses implicit.
1234567891011121314151617
class Hoge
def self.exec
raise "something is not good" if something_check
begin
ActiveRecord::Base.transaction do
User.create(username:"moge")
User.create(username:"moge")
end
rescue StandardError => e
# if database transaction has occured, this statements will be called
p "duplicate error"
end
end
end
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rexml/parent.rb:41:in `each'
p/vendor/bundle/ruby/2.0.0/gems/xrc-0.1.4/lib/xrc/client.rb:249:in `block in on_features_received': undefined method `name' for " ":REXML::Text (NoMethodError)
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rexml/parent.rb:41:in `each'
from /app/vendor/bundle/ruby/2.0.0/gems/xrc-0.1.4/lib/xrc/client.rb:247:in `on_features_received'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rexml/parsers/sax2parser.rb:142:in `call'
from /app/vendor/bundle/ruby/2.0.0/gems/xrc-0.1.4/lib/xrc/client.rb:176:in `on_received'
from /app/vendor/bundle/ruby/2.0.0/gems/xrc-0.1.4/lib/xrc/client.rb:217:in `block in connection'
from /app/vendor/bundle/ruby/2.0.0/gems/xrc-0.1.4/lib/xrc/parser.rb:78:in `call'
from /app/vendor/bundle/ruby/2.0.0/gems/xrc-0.1.4/lib/xrc/parser.rb:78:in `consume'
from /app/vendor/bundle/ruby/2.0.0/gems/xrc-0.1.4/lib/xrc/parser.rb:49:in `end_element'
from /app/vendor/bundle/ruby/2.0.0/gems/xrc-0.1.4/lib/xrc/parser.rb:26:in `block (2 levels) in bind'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rexml/parsers/sax2parser.rb:142:in `block in parse'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rexml/parsers/sax2parser.rb:142:in `parse'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rexml/parsers/sax2parser.rb:142:in `each'
from /app/vendor/bundle/ruby/2.0.0/gems/xrc-0.1.4/lib/xrc/connection.rb:38:in `parse'
from /app/vendor/bundle/ruby/2.0.0/gems/xrc-0.1.4/lib/xrc/connection.rb:34:in `start'
from /app/vendor/bundle/ruby/2.0.0/gems/xrc-0.1.4/lib/xrc/connection.rb:14:in `connect'
from /app/vendor/bundle/ruby/2.0.0/gems/ruboty-1.0.4/lib/ruboty/robot.rb:45:in `adapt'
from /app/vendor/bundle/ruby/2.0.0/gems/xrc-0.1.4/lib/xrc/client.rb:24:in `connect'
from /app/vendor/bundle/ruby/2.0.0/gems/ruboty-slack-0.1.7/lib/ruboty/adapters/slack.rb:81:in `connect'
from /app/vendor/bundle/ruby/2.0.0/gems/ruboty-slack-0.1.7/lib/ruboty/adapters/slack.rb:14:in `run'
from /app/vendor/bundle/ruby/2.0.0/gems/ruboty-1.0.4/lib/ruboty/robot.rb:22:in `run'
from /app/vendor/bundle/ruby/2.0.0/gems/ruboty-1.0.4/bin/ruboty:6:in `<top (required)>'
from /app/vendor/bundle/ruby/2.0.0/gems/ruboty-1.0.4/lib/ruboty/commands/run.rb:5:in `call'
from /app/vendor/bundle/ruby/2.0.0/bin/ruboty:23:in `load'
from /app/vendor/bundle/ruby/2.0.0/bin/ruboty:23:in `<main>'
# Fix for bug when specified japanese datetime string
# http://qiita.com/kuboon/items/1d009e2f89729fe5db78
module RailsAdmin
module Config
module Fields
module Types
class Datetime < RailsAdmin::Config::Fields::Base
## こいつを入れないと変更ない時にダメだった
def form_value
I18n.l(self.value, format:localized_date_format)
end
def localized_date_format
"%Y-%m-%d"
end
end
end
end
end
end