【发布时间】:2015-05-11 15:44:52
【问题描述】:
TL;DR我怎样才能做到这一点,以始终使用 Mongoid 在自定义控制器中返回具有设计用户模型 ID 的路由(即重定向到 localhost:3000/profiles/504026426)?
我有一个项目,它有一个社交配置文件控制器,它使用 Devise 返回一个用户 ID,但它总是抱怨 Mongoid 需要一个有效的 ID 号才能使用此路由:localhost:3000/profiles/。
# Let's say I want to return a route with id (Devise) without having
# Rails to complain that Mongoid needs to a id of some number.
# So, I have controller containing profiles in the files.
# It goes like..
class ProfilesController < ApplicationController
before_filter :authenticate_user!
# GET /profile/
def index
@user = User.find(params[:id])
end
# .. Snipped for brevity.
end
这是正确的做法吗?
【问题讨论】:
标签: ruby ruby-on-rails-4 devise mongoid