search for: find_by_usernam

Displaying 20 results from an estimated 28 matches for "find_by_usernam".

Did you mean: find_by_username
2007 Oct 26
1
Spec custom finders
...I load, or should I spec the actual query? I know that DB access is sort of frowned upon, but is this a situation where it is more or less acceptable? My spec looks something like this, but just feels funny because I''m essentially rewriting the query. describe User, ''when calling find_by_username'' do before(:each) do User.stub!(:find).and_return(nil) end it ''should convert the username to lowercase'' do uname = ''Joe'' uname.should_receive(:downcase).and_return(''joe'') User.find_by_username(uname) end...
2006 Jun 30
4
More idiomatic way of writing a filter
Is there a more elegant way of writing this? def verify_user @user = User.find_by_username params[:username] if @user.nil? message = xml.error do |xm| xm.message "User does not exists: #{params[:username]}" end render :xml => message return false else true end end Thanks, Joel -- http://wag...
2010 May 08
2
uninitialized constant - Please Help Me...
...nly certain individuals the ability to manage topics etc. That code is in the moderator_role.rb migration file which looks like this: class AddModeratorRole < ActiveRecord::Migration def self.up moderator_role = Role.create(:name => ''Moderator'') admin_user = User.find_by_username(''Admin'') admin_user.roles << moderator_role end def self.down moderator_role = Role.find_by_name(''Moderator'') admin_user = User.find_by_username(''Admin'') admin_user.roles.delete(moderator_role) moderator_role.destr...
2009 Jan 16
16
Testing arbitrary post action parameters
I am working on our (newly renamed) authentication feature. The current scenario is: Scenario: Non-administrators should not set administrator ability Given I have no users And I add a user named "admin" as an administrator And I add a user named "myuser" as not an administrator When the user named "myuser" authenticates And the user
2006 Jul 05
1
Routing via function
...', :controller => ''user'', :action => ''show'' Is there a way to perform a lookup of the username before matching on this route? I am hoping to be able to do something like this (completely made up): :requirements => {:username => {|username| User.find_by_username(username)}} I vaguely remember seeing a post a few months ago related to this but I have had no luck digging it up. Thanks, Tom Davies http://atomgiant.com http://gifthat.com
2006 Jul 22
2
fetching records from tables
Dear all, I have a doubt, How to fetch records from tables, which are not having ID field as its primary key. If possible, please tell me to way to extract data from those tables. -- with regds, Nahalingam N. Kanakavel. (http://www.nahalingam.bravehost.com/PlanetN/) -------------- next part -------------- An HTML attachment was scrubbed... URL:
2013 Jun 24
0
wrong number of arguments calling `request` (0 for 1) (ArgumentError)
...steps file When "$person logs in" do |user| post_via_redirect "/users/login", {:authenticator => {:username => user, :password => "washington"}},{:https => ''on''} request.should_not be_ssl request.session[:user_id].should == Person.find_by_username(user).id end working fine with cucumber-0.10.0 and cucumber-rails-0.3.2 but if I upgrade with cucumber-rails-1.2.1 or cucumber-rails-1.3.1 - at this line request.session[:user_id].should == Person.find_by_username(user).id I am getting bellow error. Then amitpandya should be logged in...
2006 Jul 14
4
sending additional parameters to before_filter
i am trying to create a system so that different users have different priviliges on my application. i was going to modify my authorize function so that i could pass the required role to it and have it check the current user for that role. i am using before_filter and would like to have just one function instead of writing one for each role like so: authorize(role) instead of:
2010 Jan 12
8
tips on how to write a controller test for models associated with currently logged in user
I have a controller test here: http://gist.github.com/275616, which works fine when account is an independent model, however I want: an account to be a property of user, ( and created and associated when a user is) when the user goes to /account/edit it should on edit the account of the logged in user - I can make rails do this, but I''m utterly baffled how I should alter this test to
2006 Feb 27
4
2 belongs_to to the same parent table
Hello! I have 2 table: users and buddies User: id, name, ... Buddy: id, user_id, user_buddy_id, ... So if you have 2 users 1,jack and 2,fred and fred is a buddy of jack, there is a Buddy object: id=1, user_id=1, user_buddy_id=2 I can declare only one belongs_to in Buddy and one has_many in User. And there is conflict if I had the second one (the first one is discarded) class User has_many
2008 Nov 27
7
will_paginate issue
Hi, I am trying paginate (will_paginate) users posts. It is counting and showing the page links correctly, but still showing all the posts on one page. @entries = @user.entries.paginate :per_page => 5, :page => params[:page], :order => ''created_at DESC'' If I change it to @entries = Entry.paginate :per_page => 5 ........ It is fine, but I would like to show only
2008 May 30
6
Session problem
...o everyone, I am just starting a project for school in RoR and I am a complete n00b ^^ Here''s my problem : I need to get the user''s login stored in the session but for some reason I cannot. Here''s my login method code : def login if request.post? @user = User.find_by_username(params[:login]) if @user and @user.password_is? params[:password] session[:user] = @user.id redirect_to :controller => ''games'' else @auth_error = ''Wrong username or password'' end end end And here''s the code of my GamesCo...
2006 Jun 27
0
More idiomatic way of doing this
...uire ''util/render_error'' class ApplicationController < ActionController::Base include RenderError end app/controllers/user_controller.rb: class UserController < ApplicationController before_filter :verify_user private def verify_user @user = User.find_by_username params[:username] if @user.nil? render_user_exists params[:username] false else true end end end Thanks, Joel -- http://wagerlabs.com/
2006 Apr 11
0
a user model in all controllers in 6 lines of code
...search, and making a fool out of myself; but I found a way to get a user model from the session and have it accessible in every controller and view in 6 lines of code. In the ApplicationController write model :user before_filter :set_user private def set_user @user = session[:user] ||= User.find_by_username(''nobody'') end I have redeemed myself (whoohoo!!)
2006 Jan 20
0
How to update two records ?
...rsonaldatas Is a problem with my associations? How to save personaldata with @user.save ? class User < ActiveRecord::Base has_one :personaldata end class Personaldata < ActiveRecord::Base belongs_to :user end class UserController < ApplicationController def update @user = User.find_by_username(params[:id], :include => [:personaldata]) @user.attributes = params[:personaldata] # <- doesn''t work #@user.personaldata.attributes = params[:personaldata] # <- this way it doesn''to work too if @user.save flash[:notice] = ''Updated'' red...
2006 Apr 07
3
Howto set a global parameter
Hi, In my login_controller I get the usename of the person logging in. @username = @user.name puts " DEBUG: #{@username} just logged in\n" # This works But @username seems empty when accessed from numbers_controller.rb , how to I set it to be accessible global? Or at least move the content of that variable over to another controller. Best regards, Martin
2006 Jun 09
2
unique login
Hello, I''ve created my user model which validates against the database for a proper user/pass combination. I''ve set validation options to ensure that both a user and password are entered. I would like to check via an ajax call whether or not the username is taken. I haven''t been able to find a tutorial covering this topic. Do any of you know of one? Thanks, David
2006 Apr 07
2
MSSQL activerecord uses bad syntax
Hi all, I''m trying to get rails up on mssql for a friend, does anyone have experience? We''re working on a Windows XP box with MSSQL 2000 (no service pak), and both rails (1.1) and MSSQL are on the same box. I''m running into a bug (I think) where activerecord is using this syntax: SELECT TOP 1 * FROM users WHERE (users.user = ''jbgnuumnbu'')
2010 Sep 17
0
ruby's oauth2 grant_type
...ser model class User < ActiveRecord::Base devise :database_authenticatable, :oauthable def self.find_for_accounts_oauth(access_token, signed_in_resource=nil) data = ActiveSupport::JSON.decode(access_token.get(Settings.oauth.site + Settings.oauth.access_token_path)) if user = User.find_by_username(data["username"]) user else # Create an user with a stub password. User.create!(:username => data["username"], :password => Devise.friendly_token) end end end Logs from provider Started POST "/oauth/token" for 127.0.0.1 at 2010-09-1...
2008 Aug 01
0
Help with Access Control
...self.pals.find(pal) ? true : false end #validate # errors.add_to_base("No password") if crypted_password.blank? # end # Authenticates a user by their username name and unencrypted password. Returns the user or nil. def self.authenticate(username, crypted_password) login = find_by_username(username) # need to get the salt if login expected_password = encrypted_password(crypted_password, login.salt) if login.crypted_password != expected_password login = nil end end login end def password @password end def password=(pw) @password = pw create_new_salt...