Posted in Ruby on Rails on Dec 16th, 2008
魑魅魍魎 => Br5l%R3r4 => 魑譽匈魎
ちみもうりょう => B$\”$$$&$($*:Nj8 => ちぢうなでう
Gmailからimapで取り込んだメールのタイトルなんですが、こんな感じで変換されてしまいます。JISだと決め打っても同じ結果です。 教えてくださいえらい人。
These icons link to social bookmarking sites where readers can share and discover new web pages.
These icons link to social bookmarking sites where readers can share and discover new web pages.
Read Full Post »
Posted in Ruby on Rails on Dec 1st, 2008
sudo env ARCHFLAGS=”-arch i386″ gem install mysql — –with-mysql-config=/usr/local/mysql/bin/mysql_config
これでいいはず。
(インスコしているMysqlは本家からのパッケージ版)
These icons link to social bookmarking sites where readers can share and discover new web pages.
These icons link to social bookmarking sites where readers can share and discover new web pages.
Read Full Post »
Posted in Ruby on Rails on Nov 28th, 2008
Successfully installed rake-0.8.3
Successfully installed activesupport-2.2.2
Successfully installed activerecord-2.2.2
Successfully installed actionpack-2.2.2
Successfully installed actionmailer-2.2.2
Successfully installed activeresource-2.2.2
Successfully installed rails-2.2.2
7 gems installed
Installing ri documentation for rake-0.8.3…
Installing ri documentation for activesupport-2.2.2…
Installing ri documentation for activerecord-2.2.2…
Installing ri documentation for actionpack-2.2.2…
Installing ri documentation for actionmailer-2.2.2…
Installing ri documentation for activeresource-2.2.2…
Installing RDoc documentation for rake-0.8.3…
Installing RDoc documentation for activesupport-2.2.2…
Installing RDoc documentation for activerecord-2.2.2…
Installing RDoc documentation […]
These icons link to social bookmarking sites where readers can share and discover new web pages.
Read Full Post »
Posted in Ruby on Rails on Nov 24th, 2008
携帯サイトを作ろうとこの連休ちょこちょこやってたんだけど、携帯でバットノウハウを勉強する気など全くない。どこを着地点にしようと30分ほど悩み、UTF8でcookieなしのセッション振り回しでいく事にした。SJISにすればの話もあるんだけど、(jpmobileって言うプラギンがある)絵文字嫌いだし、自分の持ってる機種と一番近く似合ったauもUTF8に対応してたので、SJISは却下した。
セッション振り回しもdocomoがcookieに対応してないっていうからそうする事にした。結局のところこの振り回しもjpmobileプラギンが一番良く出来ていたので結局インスコ。
で、完成。
http://quoice.com/mobile
もう一つやってたのが、import機能。裏方用にimportするには十分な機能が完成した。表に出すにはまだまだ。Javascript(Ajaxってつかうのなんか恥ずかしくなってきた)での作り込みが必要。なんかいいプラギンないかな。複数レコードに対応できるvaridationが出来るプラギンってないのよね。あったら教えてください。完全にJavascriptだけのフレームワークでもいいです。
These icons link to social bookmarking sites where readers can share and discover new web pages.
These icons link to social bookmarking sites where readers can share and discover new web pages.
Read Full Post »
Posted in Ruby on Rails on Nov 18th, 2008
tank_engineはiPhone向けサイト作成用のRailsプラギン。このプラギン敷居高すぎ。まずドキュメントがない。紹介しているサイトもREADMEの事しか書いてない。READMEには、iPhone判別をしてその時は.iphone.erbでレンダリングしますよ、サブドメインを理解してiphone.hogehoge.comでiPhone用のページを開きますよ、あとHelper準備してますよ、とだけ書いてある。
そのHelperのドキュメントがない。ネット上に解説メージもない。ググってみたらMOONなんとかさんが、”iPhone向けWebサイトを作る方にもお勧めのソフトウェアだ。”とか書いてあって、READMEだけでよくここまで書けるなと思いながらも、コードを読む。
Helperは基本的にゴリゴリタグを足していくだけの物。そのタグと付いてくるJSとCSSで見た目がiPhoneのシステム設定とよく似た感じになる。 ただそのタグが非常に奇妙。iUIの流れを組んでいるみたい。
はまったのが、toggleとbutton_from_hash
toggleは
こんな感じのスイッチを作ってくれる。かっこええやんと思って使ってみると、まず、form_forの中でしか使えない。jRailsが入ってないと押しても切り替わってくれない。jRailsは<%= javascript_include_tag :defaults %>の中身を自前のjQueryベースのjsに切り替えると言う結構気持ちの悪いプラギン。
button_from_hash
iPhoneでは短冊リスト作って画面右へ行くのが階層が深い方向で左上のバックボタンで戻るUIを使っているみたい。その左上のバックボタンをつくるのがbutton_from_hash。これが書くhtmlはただのリンクでちゃんと書き出しているのに、JSのほうで視覚効果を操作してるのがそれがうまく動いてくれない。
PLAIN TEXT
RUBY:
def button_from_hash(hash)
return "" if hash.blank?
is_back = (hash.delete(:back) == true)
if is_back
hash[:html_options] ||= {}
hash[:html_options][:id] = "backButton"
# hash[:html_options][:class] = "te_slide_right"
end
button_link_to(hash[:caption], hash[:url], hash[:html_options])
end
むかつくので上の様に書き換えた。視覚効果いらない。
iphone.のサブドメインをつけると 一般ブラウザでもiPhone用画面が出てくれると言う事で、
<VirtualHost *:80>
ServerName domain.com
ServerAlias iphone.domain.com
って書き換えた。そこで疑問が。iPhoneでそのページを見に行くと強制的にiPhone用のレンダリングがされるみたいなんだけど、それを解除するのはどうしたらいいんだ?
cookies["browser"] == "desktop"
だったらいいみたい。
PLAIN TEXT
RUBY:
def original
cookies["browser"] = [...]
These icons link to social bookmarking sites where readers can share and discover new web pages.
Read Full Post »
Posted in Ruby on Rails on Nov 16th, 2008
今日初めてQuoice.comをIE6で見てみたら表示ずれてた。
まず、可能な限り同一CSSで修正する。<legent>タグはあきらめ<h2>に変えたりとか。それでもうまくいかないところは、バットノウハウを調べるのも実行するのも嫌だったので、せこい対処法で対処。
ヘッダーの中、普通のCSSリンクのあとに
PLAIN TEXT
HTML:
<%- user_agent = request.user_agent.downcase -%>
<%- if user_agent =~ /msie 6\.0/ -%>
<%= "<style type='text/css'>.....</style>" %>
<%- end -%>
つまりのところ、同じCSSだったらあとに書いてあるスタイルが 実行される事を利用し同様のIE6用のスタイルを上書き。
左が適用全、右が適用後
These icons link to social bookmarking sites where readers can share and discover new web pages.
These icons link to social bookmarking sites where readers can share and discover new web pages.
Read Full Post »
Posted in Ruby on Rails on Nov 14th, 2008
http://quoice.com
つくりました。UIとかデザインとか誰か手伝ってください。
右下にある「問題」はそれのブログパーツです。
These icons link to social bookmarking sites where readers can share and discover new web pages.
These icons link to social bookmarking sites where readers can share and discover new web pages.
Read Full Post »
Posted in Ruby on Rails on Oct 18th, 2008
何でこうなるの
{"a"=>"2", "q"=>"zxcv", "tag_list"=>"zxcv", "user_id"=>1, "qtype_id"=>"2", "s"=>"zxcv"}
#<Question id: 22, q: "zxcv", a: "2", s: "zxcv", qtype_id: 2, t: 0, f: 0, user_id: nil, parent_id: nil, tree_id: nil, lft: 15, rgt: 16, deleted_at: nil, admin_deleted_at: nil, created_at: "2008-10-18 11:02:56", updated_at: "2008-10-18 11:02:56">
user_idがnilになるのがわからん
[追記]
http://d.hatena.ne.jp/kusakari/20080727/1217139232
ここに解答有り。
プラギンが悪さと気がつくまでに時間がかかった。
These icons link to social bookmarking sites where readers can share and discover new web pages.
These icons link to social bookmarking sites where readers can share and discover new web pages.
Read Full Post »
Posted in Ruby on Rails on Sep 27th, 2008
http://peepcode.com/products/draft-rails-code-review-pdf
有料のPDFですが、なかなかいいのでまとめ。Railsベカラズ集。
セッションをDB保存
間違い
デフォルトのまま。
正解
Memcachedが速いと言われるがdbとappが一緒のサーバーであればActiveRecordで十分。3つぐらいのサーバーまではActiveRecordで十分。
カスタム設定ファイルを使え
間違い
別サーバーにつなぐときにAPIキーなどをコードに書くな。
environment.rbに書いてもまだ甘い。
正解
config/config.ymlに書く
http://kpumuk.info/ruby-on-rails/flexible-application-configuration-in-ruby-on-rails/
http://blog.bleything.net/2006/06/27/dry-out-your-database-yml
繰り返す文字列には定数を使え
間違い
emailとかよく使う文字列はtypoする。この間違いを探すのは難しい。
ドメインの設定もproductionとdevelopmentでは違う。
正解
environments/development.rb、environments/production.rbに
APP_DOMAIN = '******'と違う設定をしておいて、
default_url_options[:host] = APP_DOMAIN
FROM_EMAIL,、DO_NOT_REPLY_EMAIL、 CUSTOMER_SUPPORT_EMAILとか
http://agilewebdevelopment.com/plugins/app_config
時間の記録はUTCで
間違い
ローカルゾーンで記録
正解
UTCで保存。ユーザーの時間に合わしやすいから。
environment.rb => config.active_record.default_timezone = :utc
MySQL => CONVERT_TZ
http://dev.mysql.com/doc/refman/5.0/en/time-zone-support.html
http://redhanded.hobix.com/inspect/showingPerfectTime.html
ActiveRecordをループの中に入れない
間違い
ループのなかにfindを入れない。
正解
:includeを使って結果をループで回す。:joinとか:selectも
http://railscasts.com/episodes/22
http://blog.jcoglan.com/includebydefault/
バイナリフィールドに気をつけろ
間違い
class CreatePhotos < ActiveRecord::Migration
def self.up
create_table :photos do |t|
t.column :caption, :string
t.column :data, :binary
t.column :updated_at, :datetime
end
end
こんなときに
def index
@photos = Photo.find :all
end
こんな事をしては駄目
正解
def self.find_all_for_listing
find(:all, :select => "id, caption, updated_at")
end
もしくはwith_ scopeを使う。
http://agilewebdevelopment.com/plugins/scope_out
http://www.dcmanges.com/blog/21.html
These icons link to social bookmarking sites where readers can share and discover new web pages.
These icons link to social bookmarking sites where readers can share and discover new web pages.
Read Full Post »
Posted in Ruby on Rails on Sep 22nd, 2008
Bortってやつが、"rails アプリ名"でつくられる物の代わりに最初からRESTful Authentication & AASM、Will Paginate、Rspec & Rspec-rails、Exception Notifier、Asset Packagerのプラギンが最初から入っていて、gitとpassengerを使ったcapistranoのレシピがすでに設定済みで、RESTful Authenticationのログインがユーザー名ではなくemailで行われるみたいなので使ってみる事にしました。
私はsvnで管理してたのですが、これを機にgitに移行してみる事にしました。svnにはassemblaという無料の便利なサービスがあったのですが、githubは無料なのはオープンソースのみ。ってことでgitも野良サーバー(ubuntu)にインストール。こことかここを参考にしました。passengerのインスコはここあたりを参考に。
変更が必要だったところは、
environment.rb RAILS_GEM_VERSION = '2.1.1'
(Bortは2.1.0のまま)
database.yml socket:の追加
(MySQLで使ってます)
deploy.rbのgit設定 set :repository, "ssh://hogehoge.com:ポート番号
(sshのポート番号を変えているため)
config.ymlの設定 (RESTful Authenticationのメール確認用)
ぐらいだったです。すでにlocalで起動できてます。(index.htmlが削除されているのと、ログイン関係のroutes.rbが設定済みなため)
git add .
git commit -m'first commit'
git push origin master
cap deploy:migrate
cap deploy
をやってみると、デプロイ先でもなんにもつくる前からちゃんと動いている。いやぁ簡単です。passengerでrailsサーバーの設定も楽になったし、(エラーメッセージが派手なのが気に入らないけど)gitもlocalにコミットできるしなかなか便利です。assemblaのgit版早くでないかなと思うところです。
ログイン画面はこんな感じです。Forgotten Passwordも最初から書いてあります。
[追記]1時間半
These icons link to social bookmarking sites where readers can share and discover new web pages.
These icons link to social bookmarking sites where readers can share and discover new web pages.
Read Full Post »
Posted in Ruby on Rails on Sep 5th, 2008
http://underscore.jp/diary/20080227.html
これにはまった。
These icons link to social bookmarking sites where readers can share and discover new web pages.
These icons link to social bookmarking sites where readers can share and discover new web pages.
Read Full Post »
Posted in Ruby on Rails on Sep 5th, 2008
すでに動いているRailsアプリがあって、そのデータ構造を変えたくなった場合、それもmigrateで書くのでしょうか?戻したくなったときどうするのかとか考えるとよくわからなくなってくる。そういう場合は作り直し?
These icons link to social bookmarking sites where readers can share and discover new web pages.
These icons link to social bookmarking sites where readers can share and discover new web pages.
Read Full Post »
Posted in Ruby on Rails on Aug 16th, 2008
久々の神戸大学。工学部のメインエントランスにガラスのファザードができていたり、自動車侵入防止のゲードができていたり結構かわってた。電算機センターはVX21だったのがiMac(Leopard)だった。神戸大学が山の上のせいか、お盆真っ盛りのせいか、いつも見る人は見なかった希ガス。
http://jp.rubyist.net/?KansaiWorkshop29
Scala on JRuby
Jが付くと拒否反応があるせいか、お昼の消化に酸素をとられたせいか、プロジェクタのために暗くなったせいか、全寝してしまいました。すいません。
processing
これもJが絡んでる。ってことで興味半減。
Rubyのリフレクション
私には意味不明でした。
Rack 入門
これが一番しっくり。久々の写経。Rackって便利。簡単なアプリはherokuで書いてたけど、passenger+Rackでもいいかなと思ってきた。調べないといけないのは
ERB.new(::TEMPLATE, nil, '-').result(binding)
ActiveRecord::Base.logger = Logger.new(STDOUT)
の外部もの。
得られたリンクは
http://rack.rubyforge.org/
http://mono.kmc.gr.jp/~yhara/w/?RackReferenceJa
http://mono.kmc.gr.jp/~yhara/d/?date=20080716
These icons link to social bookmarking sites where readers can share and discover new web pages.
These icons link to social bookmarking sites where readers can share and discover new web pages.
Read Full Post »
Posted in Ruby on Rails on Aug 7th, 2008
BackgrounDRbはRailsのプラギンでRails本体とは独立してバックグラウンド処理をし続けてくれる便利なプラギンです。スケジュールを組んでこの処理を実行のようなcronのようなこともやってくれるのでbotつくれるじゃんと飛びついてみました。そしてbotもつくった。ただ、気に食わないことも多々あります。
スケジュールを維持するために空クエリーをたたき続けるのです。リソースは食うは、ログは汚れまくりです。この点は導入簡単なくせにかなり気に入らない。今回つくったtwitterのbotなんてtwitterの仕様上5分に1回しか動いてないのにリソースを食い続け2時間もすればlogが1MBを超えるし、BackgrounDRbを使うのはやめにしました。
ここでHerokuの登場です。ここにbotをおきました。HerokuではBackgrounDRbは使えないみたいです。ということで、Herokuにキックを入れるサーバーを別に準備。cronで「wget --spider http://〜.heroku.com/〜」。wgetで消費するリソースはしれてるし、いい感じです。5分おきにキックするぐらいならherokuも文句いわないだろうと思っています。ということで、新しいbotを作って行こうかなと思っています。
次は、Flickrの検索結果をfeedで吐くを考えています。ではでは。
These icons link to social bookmarking sites where readers can share and discover new web pages.
These icons link to social bookmarking sites where readers can share and discover new web pages.
Read Full Post »
Posted in Ruby on Rails on Aug 6th, 2008
オリンピックが始まるということで、twitter用のbot「浜○大明神」@hamada_dmjを作ってみました。自分からは何もしないbotです。messsageがきたら返答します。現在はlocalのコンピューターで動いているだけです。BackgrounDRbのプラギンを使用しています。自分としては正規表現の勉強用です。
/鳥谷/ => "鳥谷?あいつはトレードじゃ。"
/江草/ => "江草?あいつはトレードじゃ。鳥谷も引っ付けて2個1でもいいぞ。"
/すように$|すように。$|お願いします$|お願いします。$/ => "よーし、気が向いたら叶えたろ。"
/test|てすと|テスト/ => "テストにはつきあっとれん。"
だけが登録されています。気のきいた正規表現を是非コメントで。反映します。いずれちゃんとサーバーにあげて勝手に正規表現登録できるようにする予定です。 あと、BackgrounDRbなんですが、待機中にもログを吐き続けるのですが、いい方法があったら教えてください。
These icons link to social bookmarking sites where readers can share and discover new web pages.
These icons link to social bookmarking sites where readers can share and discover new web pages.
Read Full Post »
Posted in Ruby on Rails on Jul 28th, 2008
topを眺める
tail -f log/production.logを眺める
These icons link to social bookmarking sites where readers can share and discover new web pages.
These icons link to social bookmarking sites where readers can share and discover new web pages.
Read Full Post »
Posted in Ruby on Rails on Jul 13th, 2008
PLAIN TEXT
RUBY:
def index
get_database( params[:id] )
begin
@tables = @database.tables
rescue RuntimeError
flash[:notice] = $!.to_s
redirect_to :controller => :home, :action => :databases
end
end
These icons link to social bookmarking sites where readers can share and discover new web pages.
These icons link to social bookmarking sites where readers can share and discover new web pages.
Read Full Post »
Posted in Ruby on Rails on Jul 9th, 2008
携帯の絵文字とかよくわかってないのでherokuを使ってjpmobileプラギンのテストすることにしました。上記QRコードでhttp://jpmobile.heroku.comへ飛びます。携帯で絵文字がんがん使って書き込んでください。(ついでのなんの絵文字かも)。
使ってるjpmobileは0.0.2です。
Adsenseが表示されるかどうかもテストしています。PCからだと表示されないはずです。topに表示されていたかどうかも書き込んでいただけるかもありがたいです。もしGoogleのbotがきたら http://jpmobile.heroku.com/googleに足跡を残すようにしています。判別はここを参考に同じことをしています。
Adsenseはデフォルトでchtmlにしています。
そのコードはネット上のどこかでひらったものでhelperに、
PLAIN TEXT
CODE:
require "uri"
require "open-uri"
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
def adsense
ggl={
'ad_type' => 'text_image',
'channel' => '**********',
'client' => 'ca-mb-pub-****************',
'format' => 'mobile_single',
'https' => request.env['HTTPS'] || '',
'host' => [...]
These icons link to social bookmarking sites where readers can share and discover new web pages.
Read Full Post »
Posted in Ruby on Rails on Jul 8th, 2008
とりあえずうまくいっていない。
i-mode HTMLシミュレーターIIでは表示されたりされてなかったり。
パケホウダイではない私は実機を使ってそうテストもできない。
アクセスが1秒に1アクセスぐらいあるので対応しようと思った。
とりあえずどんな機種からのアクセスがあるか見るために
PLAIN TEXT
CODE:
before_filter :filter1
def filter1
logger.info request.user_agent
end
をcontrollerにつけてみた。
portalmmm/2.0 N500iS(c20;TB) (compatible; Mediapartners-Google/2.1; +http://www.google.com/bot.html)
KDDI-CA33 UP.Browser/6.2.0.10.4 (compatible; Y!J-SRD/1.0; http://help.yahoo.co.jp/help/jp/search/indexing/indexing-27.html)
この2者ばっかり。(泣)
rails1.2系のアプリとjpmobileとの関係、adsenseの必要とするサーバー側コード、Docomoとauとsoftbankとvodafoneとwillcomとemobileの違い、全部調べないと。誰かラッパー作ってくれエロイ人。
These icons link to social bookmarking sites where readers can share and discover new web pages.
These icons link to social bookmarking sites where readers can share and discover new web pages.
Read Full Post »
Posted in Ruby on Rails on Jun 27th, 2008
PLAIN TEXT
CODE:
<% a = '<b>abcdefghijklmnopqrstuvwxyzあいうえおかきくけこ</b>
http://www.google.co.jp<br />
<a href ="http://www.yahoo.co.jp" onclick="return confirm(\'本当にですか?\');">yahoo</a>' %>
<h2>h:</h2>
<%= h a %>
<h2>simple_format:</h2>
<%= simple_format a %>
<h2>auto_link:</h2>
<%= auto_link a %>
<h2>excerpt a, "stu", 10:</h2>
<%= excerpt a, "stu", 10 %>
<h2>excerpt a, "いうえ", 5:</h2>
<%= excerpt a, "いうえ", 5 %>
<h2>highlight a, "いうえ":</h2>
<%= highlight a, "いうえ", highlighter = '<font color="red">\1</font>' %>
<h2>strip_links:</h2>
<%= strip_links a %>
<h2>sanitize:</h2>
<%= sanitize a %>
<h2>simple_format(h):</h2>
<%= simple_format (h a) [...]
These icons link to social bookmarking sites where readers can share and discover new web pages.
Read Full Post »