Displaying 20 results from an estimated 23 matches for "find_by_".
2005 Dec 14
4
find_by_ issue
In the Agile RoR book, page 219 (softcover version) they talk about the
fact you can use the methods: find_by_ and find_all_by_ and fill in the
last piece with a valid column name.
So I have a database table called "parts" and the following columns:
id
partname
partnumber
vendor
I do the following:
(connection to DB already established)
class Part < ActiveRecord::Base
end
mypart = Part.f...
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...
2008 May 22
9
Retrieving Mutliple Records using find_by_*
I was hoping that AR''s find_by_* magic methods would help me retrieve
multiple items somewhat like the following:
names_to_find = [''Larry'', ''Moe'', ''Curly'']
found_people = Person.find_by_name(names_to_find)
Is there a way to accomplish this using find_by_* (or even find(:...
2005 Mar 05
9
Best practice to manage ''id'' hacking?
...account id
or transaction id between the controller and the view.
But what is to stop someone hacking the URL or view html to access
another account id or transaction id ?
eg /account/show/46 becomes /account/show/53 or /transaction/show/44
becomes /transaction/show/77
Well, I can change every find_by_* to include the account id from the
session [is this safe, ie, what about cookie hacking?]
What other techniques are people using to cope with ''id'' hacking?
Thanks
Neville
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEA...
2007 Mar 27
6
how does rails do this "find_by_?"
Hello there,
I''m wondering how do they create functions on the fly?
find_by_any_column_name ??
I want to do something similar with my models, but I don''t really know
how to do it?
user_current_nickname
user_current_id
user_current_role
etc.?
Regards,
Jamal
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You rec...
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:
2011 Sep 22
2
find_by_email dynamic method returning new
Hello everyone,
I have a rails app which uses email as login name. At some point, I
have to search the user, in the User model by email. For some reason,
the method User.find_by_email(email) returns nil, even though the user
is in the database.
The same applies for any find_by_* method that searches by any
database column. I was able to find the user using the User.find
Does anyone have an idea of what might be going on?
thanks,
-fred
--
You received this message becau...
2008 Mar 04
6
find_all_by deprecated?
Is find_all_by deprecated and/or find_first_by for 2.0.2? If not,
what is actually deprecated? just find_all(..) and find_first()?
Thanks for clearing this up.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to
2012 Feb 23
4
Undefined Method
...:console => ''Dreamcast'')%>
the above code is repeating for each individual console.
Now in my gamescontroller I have the following in my index:
def index
@games = Game.paginate(:per_page => 4, :page =>
params[:page]).search(params[:search])
@games = @games.find_by_console(params[:console]) unless
params[:console].blank?
end
The problem I receive is that when I click on the Gaming section of my
website I receive the following error message which I assume is to say
activerecord is not connecting:
undefined method `find_by_console'' for
#<WillPagi...
2008 Feb 07
1
ActiveRecord 'find_or_initialize_by' dynamic finder bug? Ignoring conditions.
...of
two possible ''state'' values (passive || pending_singup). While trying
to implement this I discovered that the find_or_(initialize|
create)_by_* dynamic finders totally and silently ignore any
conditions passed.
Bug?
Should''nt these dynamic finders behave the same as find_by_* or
find_all_by_* dynamic finders and use the :conditions passed to them?
The documentation seems to indicate that they should.
http://api.rubyonrails.org/classes/ActiveRecord/Base.html
Dynamic attribute-based finders
"It''s even possible to use all the additional parameters to find...
2009 May 09
41
updating the db 6000 times will take few minutes ?
i am writing a test program for ActiveRecord, and it reads a document
which is like 6000 words long. And then i just tally up the words by
recordWord = Word.find_by_s(word);
if (recordWord.nil?)
recordWord = Word.new
recordWord.s = word
end
if recordWord.count.nil?
recordWord.count = 1
else
recordWord.count += 1
end
recordWord.save
and so this part loops for 6000 times... and it takes a few minutes to
run at leas...
2009 May 19
0
Extending finders to include a session variable as an option??
...ve a UI element which allows users to toggle whether or not to
display deleted Pages, their current setting being stored in a session
variable, session[:show_deleted].
What we would like is to automagically have :with_deleted => session
[:show_deleted] appended to all calls to find, all, first, find_by_
etc.
That would be easy enough to do with an alias_method_chain but for the
fact that session data is not available when the call is being made
from a model.
I know accessing session data in a model is controversial, but can
anyone suggest a workaround? Or alternatively another approach to
being...
2006 Jul 02
5
Pretty URLs -> Routes
Hi
I am having issues with getting my pretty urls to work.
routes.rb:
map.connect '':user'' , :controller => ''front'' ,
:action => ''list'' ,
:filter => ''user''
front_controller.rb:
def list
@advert_pages, @adverts = paginate :adverts, :per_page => 10
@user =
2006 Nov 16
2
dynamically adding static (class) methods to a class
Hello again,
I guess this is more of a Ruby question, but here goes anyways...
I want to intercept all calls to non existent class methods and then
call an existing class method with the non existent name.
In code...
class MyModel < ActiveRecord::Base
def MyModel.method_missing(symbol, *args)
MyModel.func(symbol.id2name)
end
def MyModel.func(func_called)
puts "You
2006 Feb 17
4
Table with Constants
...ject'', ''method'', Constants.find(:all, :select => ["key,
value"], :conditions => [''type = ?'', "sex"]) %>
I prefer to have something in the ConstantsModel to return an array like
class Constants < ActiveRecord::Base
def find_by_type (type)
find(:all, :select => ["key, value"], :conditions => [''type = ?'',
type])
end
end
Can anyone help me?
--
Posted via http://www.ruby-forum.com/.
2006 Aug 16
4
Undefined method - what undefined method
I am doing a typical database list, but when I do
<% for m in @private_messages %> (Line 28) It tells me that the method
''each'' is undefined. What''s wrong, I did not call the method each....
Here''s the error:
Showing app/views/account/mail.rhtml where line #28 raised:
undefined method `each? for #<PrivateMessage:0x408bb830>
Extracted source
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
2006 Mar 07
7
m:n or multiple 1:n?
I have a Newbee question:
i have three tables and want to connect them. so is it stupid to make a
triple m:n (rails style xs_ys_zs) or do i have to make a new table
(newtable) where i got multiple 1:n?
the habtm (has and belongs to many) do only work proper to join two
tables, or i am wrong?
-jens
--
Posted via http://www.ruby-forum.com/.
2006 Jul 11
6
@record.each do |record|
I''m trying to ''destroy'' a particular record of a table
>From the controller side, i''ve found a list of possible records that i
want deleted.
ie. @chart = Chart.find(:all, :conditions => ["record_id = ?",
param[''id''] ]
''id'' is passed into the controller and @chart is all the possible
records that have
2007 Nov 14
6
My own methods on model + "extends" problem?
Hello.
I have a UsersController and a Model called User with a "new" method,
like this:
class User < ActiveRecord::Base
def test
return 1 #I can do anything and return any data, the
problem continues.
end
end
The problem is that I cannot access my "test" function from the
controller. It says that the method doesn''t exists.
class