Displaying 20 results from an estimated 4000 matches similar to: "Active Record: finding records based on :belongs_to values"
2005 Dec 29
7
belongs_to causing NoMethodError exceptions ... ?
I''ve got a really strange problem using belongs_to. I apologize in
advance for the length... this is going to take a while to explain.
Basic idea: Creating a User requires that the user enter an email
address and activation key that matches an existing PendingUser.
After creating the user successfully, that pending user should be
marked as "used".
The problem:
When I
2008 Jul 16
2
belongs_to causing endless loop on first call to save!
Hi,
I have a situation I''m hoping someone out there may be able to shed some
light on. I have a Rails app (2.1.0 on Ruby 1.8.7) with a wizard-based sign
up process, that has recently been changed from storing incremental data in
the database to having a medium sized object graph living in the user
session until the user completes the entire sign up process (this is a
business
2006 Jun 05
2
When adding a record in console, a parameter comes in as null even when I set it
In console, I am trying to create a User but the :account_id does not come
in. Console just gives me back :account_id => nil. Obviously I''m trying to
set it though. Silly console...
But, I can set the account_id column in my controller like so:
@user = User.new(params[:user])
@user.account_id = account.id
@user.save
Here''s what I give to the controller:
User.create :name
2005 Mar 22
9
am i the only one with this problem?
(clean install)
>gem install rails
Attempting local installation of ''rails''
Local gem file not found: rails*.gem
Attempting remote installation of ''rails''
Install required dependency activesupport? [Yn] y
Install required dependency activerecord? [Yn] y
Install required dependency actionpack? [Yn] y
Install required dependency actionmailer? [Yn] y
2007 Jul 29
1
Curious why this doesn't work. (has_many, belongs_to)
Two Models.
class Gm < ActiveRecord::Base
belongs_to :pool
# mode code here.
end
class Pool < ActiveRecord::Base
has_many :gms
# mode code here.
end
Testing code through the console.
>> gm_list.each{ | gm | puts " GM name: #{ gm.user_name } belongs to Pool: #{ gm.pool.pool_name } " }; nil
GM name: John belongs to Pool: RHP 07-08 Season - Career League
GM name:
2006 Jan 11
3
How do you do a custom sql call in rails?
Hi.
I am developing an industry specific crm that allows busineses to track
customers in a particular way. Each customer will be assigned a customer
number. The first customer will have a customer number of 1, the second
customer_number = 2, etc... Note that this customer number is not global
but particular to the account that created the customer (see schema snip
below).
I need to have a
2007 Jul 09
3
NoMethodError when using find_by_sql
I''m try to verify users on login. Here is my code:
def self.authenticate(username,password,account_code)
employee = self.find(:all,
:select => "e.id, e.first_name, e.last_name, e.username,
e.account_id, e.department_id, o.pay_type_id, o.admin_yn, o.payroll_yn,
o.files_yn, o.dept_report_yn,e.salt, e.hashed_password",
:conditions => ["e.deleted_yn=0 and
2010 Dec 02
8
CanCan issue when being very specific
So I got CanCan and Devise working well. I have two types of users:
Admins and Nonadmins. Admins can edit all of Nonadmins profiles.
The problem is, every user (either Admin or Nonadmin) belongs to an
Account or Organization. Admins should only be able to edit users from
their own Account or Organization. I was able to do that too.
The problem is, I can''t display the Create New User
2009 Nov 27
2
update_attribute does not update
My server is running Rails 2.3.4...am I not doing this correctly or is
something borked?
>> c=Contact.last
=> #<Contact id: 24, name: "Larry", email: "larry-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org", phone:
2147483647, account_id: 8, created_at: "2009-11-27 18:16:25",
updated_at: "2009-11-27 18:40:08", hide_name: false, hide_phone:
false,
2006 May 12
1
superpose two variables in lattice/xyplot
Dear R users,
I try to use xyplot() to display two different response variables from
the same dataframe per panel, but don't succeed:
xyplot(ptot.seaslog ~ vmcwit | seas, data=reeks, as.table=TRUE,
panel = function(x,y){
panel.xyplot(x, y, ylim=c(0,1))
panel.superpose(x=reeks$vmcwit, y=reeks$ptotbin,
panel.groups = "panel.xyplot",
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
2008 Nov 12
5
dynamic condition for has_one and eager loading issue
Hi,
I ve defined the following relation in one of my models with a dynamic
where condition:
has_one :selection,
:foreign_key => ''object_id'',
:conditions => ''selection_type = 1 and account_id = #
{self.send(:account_id)}''
That works perfect, however when I try to eager load that relation I
am getting the following error when doing a
2008 Apr 23
0
self referential (n-n relationship) belongs many controller
Hi all,
I ve some troubles in my small acpplication (only 2 tables).
I want to follow up tasks but these tasks are linked to others tasks.
So I ve tried to do store the nn relationship in other table called
links
1st table : tasks
columns : id | infos neutral... (as title, description etc ...)
-----------------------------------------------------------------------------------
model :
class
2006 Jun 19
3
Using set_primary_key breaks acts_as_tree with non-integer column
I just switched from using the standard "id" column into using my own
primary key and generating my own unique id for each record. But, this
breaks acts_as_tree.
Because my new primary key is not an integer, it breaks the SQL query
as follows:
StatementInvalid in PagesController#create
--------------------------------------------------------------------------------------
2006 Mar 21
5
Order records based on number of children
Let''s say I have simple schema with two tables. The models are defined
like the folllowing:
class Parent < ActiveRecord::Base
has_many :children
end
class Child < ActiveRecord::Base
belongs_to :parent
end
Simple has_many relationship. Is there any way to order the results of
a Parent.find_all by the number of children the parent has? I can
sort with
sorted_parents =
2007 Dec 02
1
total_hits and conditions
Hi. I''m running 0.11.4. The problem I''m having, appears to have been solved
before according to various posts I googled up, but possibly the fix got removed
from 0.11.3 to 0.11.4?
re = Entry.multi_search(''service'', [Ticket], options, {})
re.size
620
re.total_hits
620
Now add conditions:
re = Entry.multi_search(''service'', [Ticket],
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?
2006 Apr 03
2
Fast way of finding new position for model object?
I have a model object that acts as a list. The position of each object
is determined by two factors: number of votes ascending and age of
object descending. When a user adds or deletes a vote I need to
quickly update the associated model object''s position. Right now this
is done with the following method:
def update_position
position = nil
Bug.find(:all, :order =>
2012 Sep 02
1
to_model
There''s a number of calls in the Rails source to convert_to_model,
which takes an activerecord object instance:
convert_to_model(object)
Here''s the thing. All convert_to_model does is calls to_model, which
returns self (the ActiveModel instance).
Am I missing something here? Why call a method that returns the same
thing?
@user
=> #<User id: 3, name:
2006 Jan 26
3
global objects?
Forgive the term global if that''s not applicable in rails (i come from a
php background)
I have a browse controller with a couple of different methods
def method1
@properties = Property.find_all
#other stuff for that method
end
def method2
@properties = Property.find_all
#other stuff for that method
end
def method3
@properties = Property.find_all
#other stuff for that method
end
I