カテゴリ: rails の記事
[リスト]
ruby on railsに関するメモ。
ArgumentError (A copy of ApplicationHelper has been removed from the module tree but is still active!): app/helpers/application_helper.rb:459:in `don_get_oldconfig' app/helpers/application_helper.rb:453:in `don_get_config' lib/akismet.rb:41:in `initialize'
というエラーが,JRubyでdevelopment modeで動作させたときだけ発生していた.
Commit d37ac7958fc88fdbf37a8948102f6b4e45c530b3 to rails's rails - GitHub
でなおっているらしい.
donrailsでつかっているlibxml-rubyとlibxml-xmlrpcをconfig.gemでいれられるようにしていたのだが,そのconfig.gemで指定しても,
Missing these required gems: libxml-ruby libxml-xmlrpc You're running: ruby 1.8.7.160 at /opt/local/bin/ruby rubygems 1.3.4 at /Users/yaar/.gem/ruby/1.8, /opt/local/lib/ruby/gems/1.8
といわれるのでした.
もちろんlibxml-rubyもlibxml-xmlrpcも存在している.
/opt/local/lib/ruby/gems/1.8/gems$ ls libxml-ruby* libxml-ruby-0.8.3: CHANGES RAKEFILE doc/ lib/ test/ LICENSE README ext/ setup.rb libxml-ruby-0.9.7: CHANGES README doc/ lib/ test/ LICENSE Rakefile ext/ setup.rb libxml-ruby-1.1.3: CHANGES README doc/ lib/ test/ LICENSE Rakefile ext/ setup.rb
どうやら
#LibXML Ruby - Dependency of Solr Ruby config.gem "libxml-ruby", :lib=>"xml/libxml", :version=>"~>0.8.3"
こんなかんじで中でよんでる :libの形にあわせて書け,とそういうことらしい.
config.gem "libxml-ruby", :lib=>"xml/libxml" config.gem "libxml-xmlrpc", :lib=>"xmlrpc/client"
に.変更した.これでok
研究でつかってるprogramの前哨戦で,donrailsのrails2.3化を行った.
- etchだとdebでいれたgemではだめ.gemが1.3.1よりあたらしいものを要求する.まあとってきてインストールするだけだが,それにあわせて必要なgemをいれなおさないといけない.
actionmailer (2.3.2) actionpack (2.3.2) actionwebservice (2.3.2) activerecord (2.3.2) activeresource (2.3.2) activesupport (2.3.2) hpricot (0.8.1) libxml-ruby (1.1.3) libxml-xmlrpc (0.1.5) mocha (0.9.5) mysql (2.7) packet (0.1.15) rails (2.3.2) rake (0.8.4) rubygems-update (1.3.2) will_paginate (2.2.2)
使うのはこんなかんじ. - rake rails:update
- application.rbがapplication_controller.rbを変えろ,と出た.
- actionwebservice (2.3.2)をいれる
- http://github.com/datanoise/actionwebservice/tree/master からとってきて
- 手元でbuildしてインストールする
gem build actionwebservice-2.3.2.gem gem install actionwebservice.gem --local
- security_extensionsを使うのをやめた.
- app/viewsでかきかえるためには,こうなってるところをはずさないといかん.
<%= hidden_field_tag(:session_id_validation, security_token) %>
その数は.cfardm-2:~/playground/donrails/app/views$ gfind -name \*.rhtml |xargs grep token |wc 35 324 5043かなり多いな.面倒なので,module ApplicationHelper def security_token # dummy for 2.3.2 return rand.to_s endという具合でdummyをいれた. - あとはnotes_controller.rb
protect_from_forgery :except => [:catch_trackback, :trackback, :catch_ping]
- app/viewsでかきかえるためには,こうなってるところをはずさないといかん.
- controllerの中で session :off を使うのをやめた
- Test::Unit::TestCaseがなくなったので,それを書き換え
- request.session.session_idは使えない。request.session_options[:id]を使う。
- これはwarningなのでそれに従って書き換える.
- testのときに同一のテスト関数内で2つのテストをしてるときの引数の取扱がかわった.たとえば
post :delete_article, :deleteid => {'40000' => '1'} assert_equal "<br>Not exists (no delete):40000", flash[:note2] assert_redirected_to :action => 'manage_article' post :delete_article, :hideid => {'4' => '0'}, :deleteid => nil assert_equal "<br>Hyde status:4 is 0", flash[:note2] assert_redirected_to :action => 'manage_article'こんなんじで引数を変えて,2つの postを評価しているときには,2つ目のほうには使わない引数には nil を与えるなどしてやらないといかん - RAILS_ROOT/lib を読まなくなった.
NameError (uninitialized constant ApplicationController::AntiSpam): app/controllers/application_controller.rb:199:in `don_is_spam?'
とかでたので,environment.rbをいじった.config.load_paths += %W( #{RAILS_ROOT}/lib ) - ActiveRecordで,formatというのをカラム名にできなくなった.予約語?
- dbのMigrateをやった.そしてコードもなおしまくり.
ちょっとdonrailsでrails2.3がどんなものかやってみることにした.donrailsはrailsが0.11のころから作っているので,いろんなものをひきずっていて,これで動けばまあ自分の範囲では問題ないから,というのがある.
rake rails:update をまず.
application.rbがapplication_controller.rbにかわった.
次のはまり道
load_missing_constant': uninitialized constant ActionController::AbstractRequest (NameError)
https://webrat.lighthouseapp.com/projects/10503/tickets/206-uninitialized-constant-actioncontrollerabstractrequest-nameerrorを見ると
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:440:in `load_missing_constant': uninitialized constant ActionController::AbstractRequest (NameError) from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:80:in `const_missing' from /opt/local/lib/ruby/site_ruby/1.8/action_web_service/protocol/abstract.rb:74 from /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:156:in `require' from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:521:in `new_constants_in' from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:156:in `require' from /opt/local/lib/ruby/site_ruby/1.8/action_web_service/protocol.rb:1 from /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
このaction_web_serviceの問題か?
http://github.com/datanoise/actionwebservice/tree/masterを見ると2.3.2に対応したとかかいてあるな.
とりあえず plugin install でいれた.
config/environment.rb で
# config.frameworks += [ :action_web_service, :action_mailer ]
というかんじでコメントにしたらokだった.
さて.rake testがまだなので実環境ぶっこみはまだ先だ.
本日の仕事. サーボモータが電力オーバーになるのの対処に時間をとられまくり.
というわけではまっていた
ActiveScaffold :: Describing Records: to_label
Describing Records: to_label
When ActiveScaffold needs to present a string description of a record, it searches through a common list of record properties looking for something that responds. The search set, in order, is: :to_label, :name, :label, :title, and finally :to_s. So if your schema already has one of those fields, it’ll be automatically used. But you can always define a to_label method to customize the string description.

エラー回避 date_select -- can't convert Symbol into String
に書いてあることそのまんまはまってました.>某所のCMS
というわけでfix..
- http://donrails.araki.net/archives/noteslist/page/428
- http://donrails.araki.net/archives/listpages/page/428
というのもおそらくmod_rewriteの魔境にはまってしまったのだが,1のpageが常にhttp://donrails.araki.net/archives/にredirectされるようになってしまって不便このうえなかったので..
blog記事はふつう記事にリンクを貼るので page をつかうことはないと思うけど,もし影響した人がいたらごめんなさい.
対応させました.
これで,とりあえずrails2.2対応は終了したのでやっと機能追加にはいれます.
今日やったこと.
DEPRECATION WARNING: truncate takes an option hash instead of separate length and omission arguments. (called from_run_rhtml_app47views47notes47recent_trigger_title_a46rhtml at /Users/yaar/playground/donrails-rails-2.2.2/app/views/notes/recent_trigger_title_a.rhtml:34)
ときたので,
truncate(txt, 76)となっていたところを
truncate(txt, :length => 76)にする. 他にも二箇所あったので修正.
#1458 Namespaced resources fail in production when controllers are not namespaced - Ruby on Rails - rails
(ArgumentError) "Object is not missing constant TagsController!"こまったな.たしかにdevelopment modeではこれは発生していない. http://www.nabble.com/forum/Search.jtp?query=activesupport%202.2.2%20load_missing_constant いろいろ試行錯誤してみると,どうも自分の場合は typoから移植したantispam.rbを models/comment.rbで使っていることにあるようだ.
class Comment < ActiveRecord::Base belongs_to :article validates_presence_of :author validates_length_of :password, :minimum => 4 validates_length_of :body, :minimum => 5 validates_antispam :url validates_antispam :ipaddr validates_antispam :body validates_antispam :author validates_antispam :title (略)としてるこの validates_antispamをとりあえずどけた.
rails2.0で動いてたdonrailsを2.1に対応させてみた.前もひとつやったけどdonrailsってナニなことをやっているんだなあ,という気にさせられた..
- renderの途中のpathの扱い
Rendering template within ./MT/notes Rendering notes/./MT/noteslist
というかんでpathの途中に /./ がはいるといかんようだ.- return File.join(path, theme, filename) + if path == "." + return File.join(theme, filename) ## for rails2.1 + else + return File.join(path, theme, filename) + end
- renderの処理では :inline とか :template を指定する.
application_helper.rbの中でrenderを呼んでいるときは :inline を指定してやる.
rails2.0のときは
- content += render("shared/attachments/picture", "atta" => atta)
こんなかんじでrender先でつかう変数は"hoge"でくくってやれば使えたが,rails2.1では
+ content += render(:inline => "shared/attachments/picture", :locals => {:atta => atta})
とまあ,:localsを使って指定しなければならない.
app/viewsの下でrenderを呼ぶときは,:template で指定してやる
-<%= render(don_get_theme("shared/category_title_list"), "category" => "donrails
") %>
+<%= render :template => don_get_theme("shared/category_title_list"), :locals =>
{:category => "donrails"}
- vendor/plugin/cache_testを削除
どうもrails2.1には対応していないのでざっくり削除.
というわけでなんとかなったのでrails2.2対応が次かな.