2009-12-27RailsXSSを試してみる
RailsXSSを試してみる
NZKoz's rails_xss at master - GitHub
rails2.3.5から使用できるようになったRailsXSSを試してみた。
rails3.0でも保証されるらしい。
機能としては、自動でエスケープ処理を勝手にやってくれる。
h付けても付けなくても一緒。
↓いらなくなっちゃうね。
SafeERBを使ってみる - うんたらかんたらRuby - Rubyist
以下、基本READMEに書いてあることです。
インストール
Install rails 2.3.5 or higher, or freeze rails from 2-3-stable.
Install erubis (gem install erubis)
Install this plugin (ruby script/plugin install git://github.com/NZKoz/rails_xss.git)
Report anything that breaks.
sudo gem install erubis
ruby script/plugin install git://github.com/NZKoz/rails_xss.git
エスケープ回避
rawメソッド
<%= raw some_helper %>
html_safe!
def some_helper (1..5).map do |i| "<li>#{i}</li>" end.join("\n").html_safe! end
safe_helper
module ApplicationHelper def some_helper #... end safe_helper :some_helper end
感想
便利で安心安全なので暫く使ってみようと思います。
まだあんまり使われてないんでしょうか。
記事が少ないですね。
既存のアプリに影響有りといえば有りなので
まだこれからなんでしょうか。
2009-10-05hannaとbdoc
hannaとbdoc
bdocとhannaを使ってrubygemsのrdocを快適に閲覧 - pLab blog
やってみた。
$ sudo gem install manalang-bdoc mislav-hanna #hannaを渡すとエラーとなったのでhanna以外を対象として実行。 $ gem list --no-versions | grep -v hanna | sudo xargs hanna --gems $ bdoc
installでエラー
mislav-hannaのrdocでエラーの模様。
Installing ri documentation for mislav-hanna-0.1.11... RDoc failure in lib/rubygems_plugin.rb at or around line 12 column 36 Before reporting this, could you check that the file you're documenting compiles cleanly--RDoc is not a full Ruby parser, and gets confused easily if fed invalid programs. The internal error was: /opt/local/lib/ruby/gems/1.8/gems/rdoc-2.3.0/lib/rdoc/code_objects.rb:411:in `add_require': undefined method `add_require' for nil:NilClass (NoMethodError) from /opt/local/lib/ruby/gems/1.8/gems/rdoc-2.3.0/lib/rdoc/parser/ruby.rb:2321:in `parse_require' from /opt/local/lib/ruby/gems/1.8/gems/rdoc-2.3.0/lib/rdoc/parser/ruby.rb:2455:in `parse_statements' from /opt/local/lib/ruby/gems/1.8/gems/rdoc-2.3.0/lib/rdoc/parser/ruby.rb:2208:in `parse_method'
こんな感じ
まぁ、こっちでもいい気がする
2009-10-03railroadでクラス図作成
railroadでクラス図作成
.dotファイルを作成するrailsのモデリングツール。
.dotファイルはGraphvizってツールで見たり、画像に書き出したりできる。
インストール
gem install railroad
使い方
railsのルートディレクトリで以下を実行。
railroad -o doc/controllers.dot -C
controllerでエラー
$ railroad -o doc/controllers.dot -C Error loading controller classes. (Are you running railroad on the aplication's root directory?) /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- app/controllers/application.rb (MissingSourceFile) from /opt/local/lib/ruby/vendor_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/gems/1.8/gems/railroad-0.5.0/lib/railroad/controllers_diagram.rb:39:in `load_classes' from /opt/local/lib/ruby/gems/1.8/gems/railroad-0.5.0/lib/railroad/app_diagram.rb:21:in `initialize' from /opt/local/lib/ruby/gems/1.8/gems/railroad-0.5.0/lib/railroad/controllers_diagram.rb:14:in `initialize' from /opt/local/lib/ruby/gems/1.8/gems/railroad-0.5.0/bin/railroad:38:in `new' from /opt/local/lib/ruby/gems/1.8/gems/railroad-0.5.0/bin/railroad:38 from /opt/local/bin/railroad:19:in `load' from /opt/local/bin/railroad:19
エラーメッセージから「app/controllers/application.rb」が原因のよう。
rails2.3以降、「application.rb」が「application_controller.rb」になったとこだろうと推測。
/opt/local/lib/ruby/gems/1.8/gems/railroad-0.5.0/lib/railroad/controllers_diagram.rb:39
を見てみると案の定requireしていたのでコメント
#require "app/controllers/application.rb"
解決。
こんな感じ
モデルは使えそう。
参考
2009-09-21
rails footnotes
textmateのプラグインを探していたら
凄く便利なrails pluginに出会った。
cookieやらsessionやらSQLやらlogやら何でも表示できちゃう。
こんな感じ。SQLを表示させてみた。
青色箇所がfootnotesの領域。
Edit〜をクリックするとtextmateで表示するようになっている。
<a href="txmt://open?url=file:///hogehoge/app/app/controllers/admin_controller.rb&line=2&column=3" onclick="">Controller</a>
インストール
drnic's rails-footnotes at master - GitHub
cd myapp git clone git://github.com/drnic/rails-footnotes.git vendor/plugins/footnotes rm -rf vendor/plugins/footnotes/.git
2009-09-20will_pagenateのバグって直ったの?
will_pagenateのバグって直ったの?
ここRails開発日記: will_paginate or paginating_findや
ここhas_manyにwill_paginateがだめぽい - urekatのスカンク日記3
で記載されているように
will_pagenateはhas_many時に問題があるようだ。
でも
私の環境では再現しない。作り方がわるいのかな。
バージョンは、mislav-will_paginate (2.3.11)。
(なんで名前変えたんだろう。)
ここみてもよくわからん。
Tickets - will_paginate library - sod
とりあえず
skipでも使われてるし、直ったと思って様子を見よう。
全然関係ないけど
will_paginateには、cssが用意されていてなかなか見た目もよい。
RDOCに「There are some CSS styles to get you started in the "examples/" directory.」って書いてる。
(でもsampleのリンクは切れてる)
/Library/Ruby/Gems/1.8/gems/mislav-will_paginate-2.3.11/examples/ 下にcssとapple用のgif
が格納されているのでコピーしてちょろっと編集すればすぐ使える。
flickrもどき
appleもどき