similar to: Bug? find_by_id(nil) returns object just created

Displaying 20 results from an estimated 1000 matches similar to: "Bug? find_by_id(nil) returns object just created"

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.
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
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
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
2007 Mar 07
4
Strange Problem With Unwanted, Transient Caching
Hello, I hope somebody can explain to me 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
2012 Apr 19
1
active admin undefined method `' for nil:NilClass
im working with active admin i have collection_select or dropdown box that populates the packages and crews im just wondering i why this undefined method `[]'' for nil:NilClass` i dont know what happened but it run few days ago and tested it once but now it raises this error are there possible way to solve this? def create @package = Package.find(params[:package_crew][:package_id])
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 =>
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?
2007 Dec 04
1
spec''ing shared controller methods
I want to isolate and spec methods that are shared by controllers, and live in application.rb. Whereas I usually also provide examples in individual controllers that use these methods, not necessarily all the edge cases and I''d like to isolate the examples. This is the approach I''m taking (thanks to bryanl for suggestions and http://pastie.caboo.se/123626). WDYT? This
2010 Aug 08
2
issue with rescue_action_in_public! and testing 404 responses
Hello, I''m new to rails and I''m trying to wrap my heads around how to spec controllers using RSpec (using rails 3rc1 and rspec 2.0.0.beta.19). The problem I''ve run into is when I want to test that my controllers respond with a 404 for unfound records. Whenever I run the spec, the ActiveRecord::RecordNotFound exception is not caught by rails, causing the spec
2006 Mar 01
2
Validating that a foreign key is present and ok
How do I validate that a model object''s attribute 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
2009 Apr 29
7
problem with nil.user
Hi all, I''ve put new code into my app so that an administrator will have extra privileges (administer users, edit pages). The error is: ''Couldn''t find User without an ID'' So the app is looking for a logged in user when the homepage is accessed. Heres my code: site/index view: <% if is_logged_in? and logged_in_user.has_role?(''Moderator'')
2008 Jan 13
3
right usage of bdrb
Hi, i''m going to implement a syndication-service, which will get lists in xml with some meta-data an enclosed video files, which will get encoded at the end. The syndication run will be startet every five minutes of a full hour. So i thought to build 4 Worker. One for checking which feeds to syndicate (syndication_worker) at a specific time, one for processing the list
2010 May 24
3
ActionController::DoubleRenderError
def dispfriends @myfriend=[] @myfriendlogin = [] i=0 @currentgroup = Group.find_by_id(params[:groupid]) puts @currentgroup.id @currentfriends= GroupFriend.find_all_by_user_id_and_group_id(current_user.id, @currentgroup.id) for n in @currentfriends @myfriend=n.friend_id @myusers = User.find_by_id(@myfriend) @myfriendlogin[i]=@myusers.login puts @myfriendlogin[i] i=i+1 respond_to do
2006 Jun 17
2
URL based on acts_as_tree using routes
Hi There! I''d like some feedback before I try to implement some funky rails routes based on an acts_as_tree model. I have a Page model that acts_as_tree. I''d like the URLs to look something like this: http://localhost/about-us/staff/jeff or, another example... http://localhost/what-we-do/products/our-great-cms/features/faqs/ So, as many sub-nodes the user creates,
2007 Jan 05
4
How To Spec Controllers with Finders
Given this code (which renders rjs), I''m faced with 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
2007 Nov 21
7
describe AddressesController, "handling GET /addresses" do
Hello, I''m working with scaffold generated controller test code for handling GET requests. Address is the model being tested. Address belongs_to Company, Company has_many addresses. 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 {
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
2009 Aug 04
1
Output XML to File
I am trying to read some information based on a user id, then search the database for the needed info and build an XML file. Everything seems to be working fine; I read the info, I create the xml and even spit "stuff" out to file. The issue is that the "stuff" I am writing to a file is a xml/html cross cluster #@%$ of stuff. Here is some code: if !params[:id].blank?
2008 Jan 15
6
SQLite concurrency, SQLite3::BusyException
I am currently experiencing concurrency issues after moving from MySQL to SQLite. My original program worked fined using MySQL but is now returning "SQLite3::BusyException" errors. The same result happens whether or not I enable the allow_concurrency flag. If I do manually acquire a lock on the SQLite DB the problem would disapear, but I thought that rails was supposed to handle this