search for: current_user

Displaying 20 results from an estimated 377 matches for "current_user".

2006 Jan 16
16
acts_as_authenticated current_user in a model?
What do I need to do to be able to use an acts_as_authenticated current_user in a model? Is there some sort of include or require I can do some where that would allow this? ********************************************************** Here is what I am trying to do: ********************************************************** class Setting < ActiveRecord::Base before_cre...
2011 Jul 30
22
Question about Helpers
Studying the RoR 3 Tutorial book by Michael Hartl and on page 345 there''s the code inside the SessionsHelper: _________________________________________________________ module SessionsHelper def sign_in(user) cookies.permanent.signed[:remember_token] = [user.id, user.sault] self.current_user = user end end __________________________________________________________ What is the purpose of "self" inside the session helper? I know that inside a model it refers to the class object. For example Class User < ActiveRecord::Base self.salt it refers to User.salt But when it is...
2010 Sep 03
1
Action Controller Error: undefined local variable or method `current_user'
Newbie learning Rails. I''m currently on Chp9 here: http://railstutorial.org/chapters/sign-in-sign-out#top At the end of the tutorial, rails is erroring (see below). being new to Rails and after having checked the tutorial... How do you resolve this kind of error. It''s saying current_user is not defined, and it is supposed to be defined with/Sites/sample_app/app/helpers/ sessions_helper.rb NameError in Pages#home Showing /Users/iamme/Sites/sample_app/app/views/layouts/ _header.html.erb where line #6 raised: undefined local variable or method `current_user'' for #<#&l...
2011 Jun 09
8
Fail to call
Hi, I''m trying create a user system for a future project but I have a problem when I want give to my users the "Welcome". This is my code: #application_controller class ApplicationController < ActionController::Base protect_from_forgery helper_method :current_user private def current_user_session return @current_user_session if defined?(@current_user_session) @current_user_session = UserSession.find end def current_user @current_user = current_user_session && current_user_session.user end end #welcome_controller class WelcomeCo...
2008 Jan 30
2
Where can I get "authenticate_with_http_basic"?
...#39; for #<RegisterController:0xb7578750> RAILS_ROOT: ./script/../config/.. Application Trace | Framework Trace | Full Trace /usr/local/apache2/htdocs/easyrx/lib/authenticated_system.rb:102:in `login_from_basic_auth'' /usr/local/apache2/htdocs/easyrx/lib/authenticated_system.rb:12:in `current_user'' /usr/local/apache2/htdocs/easyrx/lib/authenticated_system.rb:6:in `logged_in?'' /usr/local/apache2/htdocs/easyrx/app/controllers/ register_controller.rb:41:in `start'' How can I troubleshoot this? Below is the code for my autehnticated_system.rb file, installed by the pl...
2009 Sep 16
5
piece of code that runs only once
hi, an strange error is happening here in User model i have the following method: def falta_votar Category.find(:all) - votes.collect {|v| v.category} end and in the default.html.erb layout i have: <%= current_user.falta_votar.size %> but it only works once, when i try to access another page i get an error message saying that the falta_votar method is nil, then i have to restart the server to access the site why is this happening?
2010 Apr 16
4
DEEEEPLY nested
Hello, i have "a" has many "b", "b" has many "c", and "c" has many "d" Now... "d" is a user model, and I have a current_user helper method defined. If i navigate to an "a" show page, how can I make sure that my current_user ("d") is part of that "a"? meaning how can i make sure that current_user belongs to "a"? Because there is the b, and c in between the "d" and "...
2007 Jul 24
6
Mocking Access Control
I''m trying to jump on the TDD/BDD bandwagon, but am having trouble understanding how i should mock my user. The user has a habtm relationship to a roles model (acl_system2 plugin), but I''m not sure how to tell rspec about a model. My code: describe UsersController do integrate_views before(:each) do @user = mock_model(User)
2012 Aug 07
9
How do I force link_to/form helpers to use the superclass name in the path instead subclass?
I want my helpers to generate paths using a superclass instead of the subclasses. Assuming I have Owner and Member that both inherit from User, rails will use the current objects class name when generating paths: Let''s say current_user is a mod: <%= link_to current_user.name, current_user %> will generate "/mod/:id". I want to force it to generate "/user/:id" regardless of the subclass. I can name the path: <%= link_to current_user.name, user_path(current_user) %> But I still want to use the co...
2007 Aug 23
3
recording current_user
Hi, Another noob here I am afraid! I have a questuin about the current_user method that comes with AAA. I have AAA set up and working fine and if i put <%= self.current_user.login %> into a view it shows the login name as expected on the page. What I cant work out is how to record this into the database when the user completes a form. My app so far only has two mo...
2007 Dec 03
18
Need help mocking this out
Let''s say you''re using the restful_authentication plugin. You have a model called articles. On the index action of the articlescontroller you simply want to spec out that it''ll scope the results to the ownership of the current_user. It should NOT include any articles other than the articles that user owns. How would you properly spec this out? Thanks for the help! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071203/1d33f697/attachme...
2012 Mar 09
2
ActionMailer message delivery content
...thing between the <% %> is what I wish to include and was wondering if anyone could point me in the right direction and tell me which are those that are correct and are not. Any help would be wonderful. The message I want to send is as followed: Hello <%@user.username%> The user <% current_user.username %> has registered an interest in the following product of yours: <% @book.book_name %> <% @book.genre %> The user <% current_user.usernames %> has the following games for offer: <% current_user.book.book_name %> To view <% current_user.username %> prof...
2007 Aug 21
2
using restful_authentication current_user inside controller specs
...rs in my application rhtml: before_filter :login_required around_filter :set_timezone around_filter :catch_errors Currently I have them commented out while rspec''in but I''ll need to add them in my specs. def create @ticket = Ticket.new(params[:ticket]) @ticket.user = current_user if @ticket.save redirect_to tickets_path else render new_ticket_path(params[:user_id]) end end describe TicketsController, "handling POST /tickets" do before do @ticket = mock_model(Ticket, :save => true) @current_user = mock_model(User) @pa...
2006 Oct 09
5
Problem setting variables in ApplicationController.
I''m dynamically generating menu options based on the currently logged in user: current_user. My menus are setup on the applicatin.rhtml file. The current_user is defined in the application controller. But, attempting to assign it a value while in the application controller results in an ''undefined method'' error. ApplicationController .... def current_user @cu = ::U...
2009 Oct 18
4
NoMethodError in User sessionsController#new
I''m setting up authentication with Authlogic and I get this error. I''ve done some searching but with no success. I tried setting the current_user method in Application_controller to protected and not private, on the recommendation in Stack Overflow. Error in browser----------------- NoMethodError in User sessionsController#new undefined method `require_no_user'' for #<UserSessionsController: 0x24fc700> Error in terminal----...
2008 Jan 23
18
Not seeing the failure
...create a new coupon from the form parameters, then set the current user. Here''s the spec: describe CouponController, "When posting to save_coupon" do before(:each) do @expectedName = "pepper''s" @expectedAmount = 5 coupon = mock_model Coupon current_user = mock_model User controller.stub!(:current_user).and_return(current_user) Coupon.should_receive (:new).with({"name"=>@expectedName,"amount"=>@expectedAmount}).and_return(coupon) coupon.should_receive(:user).with(current_user) coupon.should_receive(:save)...
2006 Jun 02
6
Set instance variable for all actions in the Controller
Can I set an application wide instance variable that is available for all actions...and their views? eg. class ApplicationController < ActionController::Base @current_user = User.find(session[:user_id]) end and everywhere I can call @current_user.id and I can get that object? Even down in the views? I could not get this to work... Thanks in advance, Jeff -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/p...
2006 Aug 16
3
calculate method is gone once I use ''find''?
Could someone please explain why this works: current_user.accounts.sum(:balance) But not this: current_user.accounts.find_all_by_active(true).sum(:balance) For the latter Rails tells me sum is an undefined method. It seems like I lose the ActiveRecord methods when I call ''find''? This (simpler) does not work either: current_user.acc...
2005 Mar 23
1
Problems with Excel & MS Word files (still)
Problem is apparently with locking issues, disabled oplocks in the [general] section, and the problem actually got worse... Here's what happens: User-A part of group1, opens Excel file off of share, saves, exits... User-B (or even User-A for that matter) tries to re-open same file, get error stating it's locked and can only open for read-only access... Both users in the same group, and
2006 Mar 16
6
Sessions or lookups?
My application needs to know if a user is an administrator, for security and aesthetic reasons. At the moment, I store true/false in the session by doing the following at login: session[:user_is_admin] = authenticated_user.is_admin? Is this OK to do? Or should I really be doing the following every time: User.find(session[:user_id]).is_admin? (user_id is always in the session too) Is there