similar to: catch "find" exception

Displaying 20 results from an estimated 8000 matches similar to: "catch "find" exception"

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
2006 Apr 17
1
Resize pictures in the client end
Ok, I put all my questions all in once now, please bear with me. The Q is: When upload a picture, can we resize the picture in the client side before send to server? Can we even convert pictures to other format on the client side with in a browser. Or I have to have a client software to do that. thx. -- Posted via http://www.ruby-forum.com/.
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'')
2013 May 28
3
AR's find_by_* limits return results. How to avoid id?
When I use find_by_name method I get LIMIT 1 result. > SELECT "users".* FROM "users" WHERE "users"."age" = 25 LIMIT 1 But the "age" column is not unique in my table and its value may repeat. So I expect that an array of records where "age" is 25 will be returned. But AR limits the query by 1. How to avoid it? Or is it the default
2006 Apr 29
11
Multiple actions from one form - possible?
Hello * Obviously the rhtml below does not work, but it should be apparent what I try to achieve - I would like to give the user the choice to submit a form either to action1 or action2 but I cannot figure out how?! It would be great if someone could give some assistance. Thanks a lot, Alex <%= start_form_tag :action1 => ''save'', :action2 =>
2010 Jun 29
16
problem finding find current page
I have this bit of code in my email.controller user = @current_user story = @current_story recipient = story.user It doesn''t work because @current_story isn''t defined. How can I find the current page to make this work? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
2007 Sep 10
6
RSpec view spec writing problem (unable to generate url_for in RESTful resource link_to)
Thanks, first, to everyone who''s asked and answered questions on this list, and to the creators of RSpec - it is all very helpful. I''ve searched the mailing list, and had a couple 2hr googling sessions that didn''t help me find an answer. I''ve run into a problem getting my first non-trivial view spec to run. I get an error when trying to generate a link_to()
2010 Jun 17
7
Why do rails calls a method when I'm calling a property?
Well, I''m starting on RoR, so I got a Book called simply rails...Following the steps in it sometimes when I try to call a property, the browser shows me the next exception: undefined method `name'' for nil:NilClass I don''t know why...here''s my controller: #Controller starts here class StoriesController < ApplicationController before_filter :login_required,
2006 Apr 15
4
sql injection
Hi, All through my current project, I''ve been assuming that rails is clever enough to prevent SQL injections automatically. Is this right? If not, what''s the best way of doing it? -Nathan
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
2006 Apr 10
5
ActiveRecord: Behavior not doumented
Hello everbody, doing a #find(:first,an_id) with Rails 1.1.0 I expected that find returns the record which id mathches the given parameter an_id or nil if it couldn''t be found. This behaviour is documented on api.rubyonrails.org. But the find returns the first available object and not nil if an_id is not in the db. Is the doc on rubyonrails.org out of sync? Greetings, -- Daniel
2010 Dec 20
4
Subselection by URL
Hey guys, I''m quite new in RoR, so please excuse me when I may ask weird questions. I am working on a database frontend. The layout looks mostly like a has_many bs b has_many cs c has_many ds and so on. Now I want to do some selection. Maybe I want to see all ds belonging to a specific b. I would like to do it like: http://my.host/bs/1/ds When I click around there (add new ds, show a d
2010 Nov 20
6
syntax error, unexpected tSTRING_BEG
Rails is throwing this error C:/Ruby/Depot/app/views/products/index.html.erb:28: syntax error, unexpected tSTRING_BEG, expecting keyword_do or ''{'' or ''('' ...er.privilege == 50 ? {link_to ''Show'', product} : ''a'' );@out... in line <%= current_user.privilege == 50 ? {link_to ''Show'', product} :
2006 Apr 12
2
Handle null item
Hi, How to i handle a find that returns a null? Say i put 40 into the paramter id below and there is no post with an id of 40 i get an error saying no post exists with id @post = Post.find(params[:id]) Anyone help?? -- Posted via http://www.ruby-forum.com/.
2006 Aug 02
3
find_by_column_name and for loop returns undef method `each''
I''m trying to understand how to select only certain rows in my database using RoR. As a test I try to find certain clients by adding this code in my list view... <% clientlist = Client.find_by_client_status_id(1) %> <% if clientlist %> <= This prevents me from getting nil errors. <% for client in clientlist %> <= This seems to try and call
2006 May 31
3
detecting changed data
I am working on an application where there are many different screens to access the data in a particular record/row. I have links to each data entry screen at the top. Is there a way to detect whether the current hash has been changed from the stored record so I can prompt the user if they attempt to change screens without having saved their changes to the data? Craig
2006 Apr 20
2
table that have many-to-may relationship to itself
In a social netowrk data model, users belongs other users, and can have many friends as users, so it is a many to many relatioship. the class definition could be class User < ApplicationController has_mang_ang_belongs_to users But how it looks like in the mysql database tables in a "joined" users table. The question really is: what is the table looks like when a model has
2006 Apr 29
3
Geolocation -- hostip.info code for rails
Hi there, I''ve put code together for using the hostip.info data under Rails. Hostip.info is a community-based project to geolocate IP addresses, making the database freely available. This database allows to translate IP addresses to city/country/longitude and latitude. It can be downloaded from the hostip.info website. They have PHP code so far to make any use of it. My code can be
2008 Feb 08
4
x-post : find_or_initialize_by ActiveRecord bug? Ignores :conditions
Hello, I posted this on the rails talk group but received no response. Perhaps someone on this list could weigh in on whether this is expected/desired behavior or a bug that I should file and develop failing tests for (I doubt I have the active record method_missing fu to actually patch it). Test Scenario: I would like to find or initialize a new user and base the find on the users email
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