March 2010
9 posts
1 tag
rails3.0betaでハマリ(find_byよりwhereがいいみたい)
controllerで @posts = Post.find_by_user_id(login.id)  # SELECT "posts".* FROM "posts" WHERE ("posts"."user_id" = 1) LIMIT 1 こう書いて、viewで @posts.each do |post| こう書いてたら、 undefined method `each' for と意味不明なエラー @posts = Post.where("user_id =?", login.id)  # SELECT "posts".* FROM "posts" WHERE (user_id =1) こう書き直すと直った。かなり時間が取られた。皆さん気をつけましょう。
Mar 29th
1 note
1 tag
rails3.0betaでActionMailerを試してみた
前回に引き続きActionMailerを試してみました。ソースはここ。 rails g mailer notifier でapp/mailers/notifier.rb と app/views/notifierができる。(modelsにできないのが新しい) こんな感じで書いておくと問題なくメールが送れる。 ヘッダーはこんな感じ。 Subject: Password Reset Instructions Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8"; Content-Transfer-Encoding: 7bit 問題は:subjectに日本語を入れた場合、 /app/mailers/notifier.rb:8: invalid multibyte char (US-ASCII) ...
Mar 26th
1 note
1 tag
routes.rbでの注記
railsでのroute.rbでしてしまったタイポから気になったとこを少々。 resources :productsと書いた場合rake routesは GET /products(.:format) {:controller=>"products", :action=>"index"} products POST /products(.:format) {:controller=>"products", :action=>"create"} new_product GET /products/new(.:format) {:controller=>"products", :action=>"new"} GET ...
Mar 25th
2 tags
authlogicでログインログアウトを実装
前回に続き少しばかり進歩させました。ソースはここにおいてます。ここを参考にしました。 urlの設計はtumblrを意識してみました。 config/routes.rb :as => ‘login’ って書いておくと、login_pathが’/login’までの相対パスの、login_urlが絶対パスのurlが表示されます。 tumblrを意識しているのでloginはemailとpasswordでの実装です。この際、 app/models/user.rb と書く必要があります。 次回はforgot_passwordを実装したいです。パスワードのリマインダをメール送信します。TMailからMailに取って代わったようなので日本語も含めていろいろテストしてみたいです。
Mar 21st
1 note
2 tags
rails3.0betaでauthlogicを試してみました
せっかくなのでrails3の勉強もかねてauthlogicが使えるかどうか試してみました。今のところ大丈夫そうです。rails3がでるまでにログイン認証のつくり込みができればと考えています。 前回作成した環境で動かしています。Lucid alpha 3+ruby1.9.1+rails3.0betaです。3月21日時点、Lucid alpha 3インスコ後sudo aptitude updateとsudo aptitude upgradeをかますとvm上でも画面が表示されるようになってます。 ではスタート。 rails r3b_authtest rails plugin install git://github.com/binarylogic/authlogic.git あとは基本的に http://github.com/binarylogic/authlogic_example...
Mar 20th
3 notes
Rose-Tinted: Upgrading to Rails 3 beta (part 2) →
This is the second part of a series of posts detailing my experiences while upgrading to Rails 3. The first part covered migrated configuration and framework files to play nicely with the new Rails 3 APIs. Now, we’ll look at booting the server, fixing dependency issues and walking through our…
Mar 20th
1 note
1 tag
とりあえずrails3をつかってみる
rails user これでuserプロジェクトができる。 rails c で前の script/console、 rails s で前の script/server Gemfileというのがある。これに必要なgemを書き込んでおくと、 sudo bundle install で 必要なgemがシステムにインストールされる。 bundle package で必要なgemが vendor/cache にインストールされる。 rails plugin install でプラギンのインスコ。
Mar 14th
1 tag
lucidにruby1.9.1とrails3.0betaをいれてみた
ubuntu 10.04 alpha3でやっとserver版がvmware上にインスコできるようになったので(画面はまだ表示されないけどopenssh-serverを入れとくとアクセスはできる)、ruby1.9.1とrails3.0betaを入れてみました。 まずは基本環境 sudo aptitude update sudo aptitude upgrade sudo aptitude install open-vm-tools 次にmysql、sqlite3、imagemagick、gitをインストール sudo aptitude install sqlite3 libsqlite3-dev mysql-server libmysqlclient16-dev sudo aptitude install libmagick9-dev sudo aptitude install...
Mar 8th
Mar 1st