rails:2671
From: roppongitoppogi@y...
Date: Sat, 10 May 2008 15:30:10 +0900 (JST)
Subject: [rails:2671] script/console で OK な SQL が、 Class.find(〜) では「 Couldn't find Class without an ID 」エラー
ぱんです
休日の昼下がり、いかがお過ごしでしょうか。
質問ばかりで恐縮ですが、よろしくお願いします。
さて、
一週間以内に作成されたレコードを表示するページが作りたく
て;
--------------------
# notes_controller.rb
def weekly
@note_a_week = [0, -1, -2, -3, -4, -5, -6]
@weekly = []
for day in @note_a_week do
if day == 0
res = Note.find(:all, :conditions => ["created_on
= ?", Time.today])
else
res = Note.find(:all, :conditions => ["created_on
= ?", Time.today + day])
end
@weekly << res
end
end
--------------------
--------------------
# weekly.rhtml
<% for day in @weekly %>
<% for note in day %>
<%= note.created_on %>| <%= note.subject %><br />
<% end %>
<% end %>
--------------------
としたのですが、notes/weeklyをブラウザで叩くと
「Couldn't find Note without an ID」エラーとなります。
ちなみに、ruby script/consoleで;
--------------------
>> Note.find(:all, :conditions => ["created_on = ?",
Time.today])
--------------------
とすると、正しく機能します。
根本的なRailsの仕組みが理解できていないのだと、我ながら
想像できるのですが、何卒お導き下さい。。。
よろしくお願いします。
--------------------------------------
GANBARE! NIPPON! Win your ticket to Olympic Games 2008.
http://pr.mail.yahoo.co.jp/ganbare-nippon/
--
ML: rails@r...
使い方: http://QuickML.com/
2670 2008-05-09 17:50 [moronatural@g... ] [ANN] Rails勉強会@東京を5/18(日)に大森で実施します -> 2671 2008-05-10 08:30 ┗[roppongitoppogi@y...] script/console で OK な SQL が、 Class.find(〜) では「 Couldn't find Class without an ID 」エラー 2673 2008-05-10 10:51 ┗[ofl@c... ] 2674 2008-05-10 11:37 ┗[roppongitoppogi@y...] 2675 2008-05-10 11:44 ┗[roppongitoppogi@y...] 2676 2008-05-10 12:23 ┗[aliasdice@m... ] 2677 2008-05-10 14:39 ┗[roppongitoppogi@y...] 2678 2008-05-10 18:55 ┗[aliasdice@m... ]