search for: find_by_id

Displaying 20 results from an estimated 126 matches for "find_by_id".

2006 Jul 30
1
Bug? find_by_id(nil) returns object just created
Tried to submit a ticket in Trac, but it reported an error... Doing a Model.find_by_id(nil) after creating an object of type Model returns that object -- and the next time, returns nil. It should always return nil. For example, Step 1. Create an object: >> Foo.create(:name => "bar") => #<Foo:0x2aaaac3ade20 @new_record=false, @errors=#<ActiveRecord::Erro...
2007 Mar 07
4
Strange Problem With Unwanted, Transient Caching
...what''s going on here because I''m baffled! In a controller''s action I want to create a new order for a customer. Because I post back to the same action (not RESTful I know, but that''s for another day) I use code like this: def edit @order = Order.find_by_id(params[:id]) || Order.new ... end I noticed that when params[:id] is nil, the finder still retrieves an order -- the order whose id matches the :customer_id which is in my params hash. Weird. I then noticed that if I ran the finder a second time, it correctly returned nil. Weirder...
2006 Jul 13
2
find_by_id(nil) does not always return nil
I have a model named User. When running this application from the console I can call User.find_by_id(nil) and it returns nil. When running this application during testing or through WEBrick or Mongrel calling User.find_by_id(nil) returns the newest record in the database. But it only does this the first time you call it with nil. The second time you call User.find_by_id(nil) it returns nil. I...
2006 Jun 27
3
find_by_id vs. find in postback action
I''m playing around with the Postback action recipe listed in the recipes book. Here is the default code given: def edit @recipe = Recipe.find_by_id(params[:id]) || Recipe.new if request.post? @recipe.attributes = params[:recipe] redirect_to :main_url and return if @recipe.save end end Here is what my code sort of ended up looking like, altho i''ve ripped it apart so many times now trying to figure it out: def edit...
2006 Jun 19
4
DateTimes get converted to Dates in XML-RPC????
Hi all - I have written an XML-RPC app using action-web-service. Mostly works well. Except I just noticed that my :datetime types are coming back as :date types. That is, when in the console I query the record via Foo.find_by_id(123) I get back actual datetimes. If I then do it via XML-RPC, fetching that same record I get back dates (ie. hour/minute/second are set to 00:00:00) Any ideas? Tried google, and ruby-forum is down and am up against a deadline... My api/model method looks like this: def find_by_id...
2007 Jan 05
4
How To Spec Controllers with Finders
...th the fixture- driven way of spec-ing or mocking. How the heck to you mock this so the code at line (2) and (4) work right? I''m still struggling with mocks but it seems like this can be done. Forgive the naivety of this question. 1. def change_quantity 2. @line_item = LineItem.find_by_id(params[:id]) 3. unless @line_item.nil? 4. @line_item.update_attribute(:quantity, params[:quantity]) 5. @extension_id = "extension#{params[:id]}" 6. end 7. end Thanks
2006 Apr 01
0
Okay, what gives? find_by_id is failing.
This has the look of a "just don''t quite get it yet" problem. I am using the ActiveRecord.find_by_id method to identify the parent object (Quiz) to tie to the child object (Question) at create time. Here is the stdout log: 127.0.0.1 - - [31/Mar/2006:22:43:22 CST] "GET /question/new? parent_quiz=ff2d7022-be0a-11da-9f01-00400506faf5 HTTP/1.1" 200 806 http://localhost:3000/questions?paren...
2009 Dec 28
2
Override .find, .find_by_id, etc...
I read these: http://www.ruby-forum.com/topic/185297#new http://www.freezzo.com/2008/05/14/override-default-find-conditions-for-model/ it works, it override the .find perfectly, however it does not cover .find_by_id or other .find_by_XXX Is there anyway to override all the find function of a modal? I want to set the default "select" for User modal, only return name and id, but not the password by default. Thanks -- Posted via http://www.ruby-forum.com/. -- You received this message because you a...
2007 Nov 21
7
describe AddressesController, "handling GET /addresses" do
...In my addresses_controller I have: before_filter :get_company def index @addresses = @company.addresses.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @addresses } end end private def get_company @company = Company.find_by_id(params[:company_id]) end My controller spec code for handling GET /addresses: before do @company = mock_model(Company) @addresses = mock("addresses") @company.stub!(:addresses).and_return(@addresses) Company.stub!(:find).and_return(@company) end def do_get...
2012 Aug 01
2
'redirect_to' taking infinite loop.
Hi, The following controller method taking me into infinite loop. Once the update action completes I want to reload the ''index'' page. May I know why it is going into infinite loop? def update Device.find_by_id( params[:device_id] ).driver = ( params[:driver_id] == 0 ) ? nil : Driver.find_by_id( params[:driver_id] ) redirect_to :action => :index, :tab => ''limo'' end Thanks, Ajit -- Posted via http://www.ruby-forum.com/. -- You received this message because you are sub...
2007 Dec 04
1
spec''ing shared controller methods
...rams[:account_id], which may be used by any number of other controllers in my app. As you can see, the filter is still getting spec''d and has pending examples. ## application.rb class ApplicationController < ActionController::Base ... def find_account @account = Account.find_by_id( params[:account_id]) # TODO: check account status is suspended, closed, different flash message? return( error_redirect_gracefully( "Account not found")) unless @account end ... end ## application_controller_spec.rb require File.dirname(__FILE__) + ''/../sp...
2007 Dec 22
8
Rails 2.0 rescue_from
I am trying to use the new Rails 2.0 macro : rescue_from class PostsController < ApplicationController rescue_from ActiveRecord::RecordNotFound, :with => :deny_access ... def show @post = Post.find_by_id(params[:id]) raise ActiveRecord::RecordNotFound if @post.nil? #illegal access ..... end def deny_access respond_to do |format| format.html end end but the exception is not raised ... did I miss something ? thanks kad -- Posted via http://www.ruby-forum.com/. --~--~---...
2008 May 16
3
has_one and find_by_id issue
I have two models: testamonial photo (has_attachement) testamonial has_one photo The issue is when do this: @testamonial = Testamonial.find_all_by_id(id) I get "undefined method `photo'' for" in my browser?? BUT here is the big kicker.... If I do @testamonial = Testamonial.find(:first) everything works fine and the image is show!.. (find :all works too when I loop
2007 Apr 11
10
DRYer controller specs
So, I''ve been following the recommendations for controller specs here: http://blog.davidchelimsky.net/articles/2006/11/09/tutorial-rspec-stubs-and-mocks Most notably: a single expectation per specify block; the setup block contains only stubs; mock expectations each get their own specify block. (I''m still using 0.8, so I haven''t gotten the describe/it goodness yet.) I
2007 May 04
11
spec template for CRUD?
Hello, Has anyone already come up with a set of shared behaviours that someone could leverage when adhering to a CRUD concept, with respect to controllers? Relatedly, it would be nice if there were a way to share generalized behaviour specs. -Chris
2006 Mar 01
2
Validating that a foreign key is present and ok
...te is a valid foreign key? The problem is, I can''t check if the attribute is a valid foreign key if the attribute doesn''t even exist. For example, every employee must be in a department. In the following code, if an employee''s department_id is not present then Department.find_by_id(department_id) might cause problems, yes? class Employee < ActiveRecord::Base validates_presence_of :department_id def validate errors.add(:department_id) unless Department.find_by_id(department_id) end end department_id should be present, a positive integer, and a valid foreign key...
2006 Jul 16
9
acl_system help is needed
i found Ezra''s acl_system plugin yesterday and i am trying to figure it out. based on the simple instructions on the site, it does exactly what i need but i''m getting some errors when i try to use it: NoMethodError in UsersController#index You have a nil object when you didn''t expect it! The error occured while evaluating nil.roles i am pretty new to rails and
2008 Jan 13
3
right usage of bdrb
...ication.id) end end - - - - - - - import_worker.rb - - - - - - - class ImportWorker < BackgrounDRb::MetaWorker set_worker_name :import_worker def create(args = nil) # this method is called, when worker is loaded for the first time end def import(feedid) feed = Feed.find_by_id(feedid) # fetch feed feed.items.each do |item| # create item MiddleMan.ask_work(:worker => download_worker, :worker_method => download, :data => item.id) end end - - - - - - - download_worker.rb - - - - - - - class DownloadWorker < BackgrounDRb::MetaWor...
2008 Jan 15
6
SQLite concurrency, SQLite3::BusyException
...owing code (shortened for clarity purposes) caused no exception with MySQL but would not run with SQLite. Is this a rails issue or is it simply normal behavior? ----- lib/person_updator.rb ----- class PersonUpdator def self.start ActiveRecord::Base.allow_concurrency = true p1 = Person.find_by_id(1) p2 = Person.find_by_id(2) t = Thread.start do 5.times do p1.name = "Michael" p1.save end end 5.times do p2.name = "Joe" p2.save end t.join end end --------------------------------- C:\test>ruby script\run...
2006 Jun 17
2
URL based on acts_as_tree using routes
...9;, :controller => ''pages'', :action => ''view'', :acts_as_tree => { :model => Page, :write_url_for => Page.name, :root_id => 0, :default_url => Page.find_by_id(:first) } OR, with a URL prefix such as "pages": map.connect ''pages/:acts_as_tree'', :controller => ''pages'', :action => ''view'', :acts_as_tree => { :model => Page, :write_url_for => Page...