I'm trying to implement Devise but new to it.

When I request .../api/v1/projects.json, I get 'undefined method
admin? for nil:NilClass', which I'm assuming happens because
params[:token] is not being set. See below for code snippets -- does
anyone know how/where to set params[:token] with Devise?


class Api::V1::ProjectsController < Api::V1::BaseController
def index
respond_with(Project.for(current_user))
end
end

--

class Project < ActiveRecord::Base
...

def self.for(user)
user.admin? ? Project : Project.readable_by(user)
end
end

--

class User < ActiveRecord::Base
before_save :ensure_authentication_token


devise :database_authenticatable, :registerable, :token_authenticatable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable
...

end

--

class Api::V1::BaseController < ActionController::Base
before_filter :authenticate_user

respond_to :json

private

def authenticate_user
@current_user =
User.find_by_authentication_token(params[:token])
end

def current_user
@current_user
end

end

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedNov 2, '11 at 6:19a
activeNov 2, '11 at 6:19a
posts1
users1
websiterubyonrails.org
irc#RubyOnRails

1 user in discussion

Tyler Warnock: 1 post

People

Translate

site design / logo © 2021 Grokbase