【发布时间】:2010-09-05 21:45:53
【问题描述】:
我是 Rails 新手......这就是我想要做的......
我为笔记创建了一个脚手架(t.text :content, t.integer :user_id)
我现在要做的只是允许用户查看他们创建的笔记。即(== user_id)
在我的 /app/controllers/notes_controller.rb 中
我有以下:
class NotesController < ApplicationController
before_filter :authenticate
before_filter :correct_user
.
.
.
.
def correct_user
@noteuserid = Note.find(:conditions=>["note.user_id=?", @noteuserid])
redirect_to(root_path) unless current_user?(@noteuserid)
end
我在理解如何编写以下行时遇到问题:@noteuserid = Note.find(:conditions=>["note.user_id=?", @noteuserid])
有什么想法吗?
谢谢
【问题讨论】:
-
不应该这样工作吗? Note.where(["user_id = ?", current_user])
标签: ruby-on-rails ruby-on-rails-3