Displaying 20 results from an estimated 400 matches similar to: "Validating a required relationship."
2006 Jun 22
3
attr_boolean, a good idea?
Hello all,
I''ve recently been working with a model with a lot of boolean  
attributes and I decided that it''s worth trying to implement a  
attr_boolean function to cut down on the work.  Something like
class User < ActiveRecord::Base
	attr_boolean :contact_by_email, :display_real_name, :administrator
end
which would replace the hand written
class User <
2006 Jul 19
1
Testing the flash is brittle?
Hello all,
I seem to have an annoying habit of realizing that I''ve asked a  
question with a blindingly obvious answer just after I''ve asked it  
but here goes.
I''ve noticed that in my functional tests there''s the occasional  
reliance on the contents of the flash.  For example, I have an action  
that confirms a users identity and may reject them because
A)
2006 Jul 12
7
Failure in comparisons
I''m basically a Ruby noobie.
At the moment I''m having a fair bit of trouble trying to figure out 
what''s going wrong here (partial template):
<%=
    @project = Project.find(@the_id)
    if current_user.userid == @project.client
      hidden_field ''messages'', ''recipient'', ''value'' => 
@project.project_manager
 
2005 Feb 09
1
cant map foreign key in list view
Hi
I have been struggling to get a foreign key in a list map to a readable
value in a lookup table
 
I have a list of projects and each project has a project_manager. 
 
Project.rb
class Project < ActiveRecord::Base
    has_one :project_manager, :class_name => "Users", :foreign_key =>
"manager_id"
end
 
The association above sais that a project_manager is in
2006 Dec 06
2
validates_uniqueness_of where scope euqals created_by "magic" field
I have the following ActiveRecord objects:
class Recipe < ActiveRecord::Base
  has_many :ratings, :dependent => true
  . . .
end
class Rating < ActiveRecord::Base
  validates_uniqueness_of :created_by, :scope => :recipe_id
  belongs_to :recipe, :counter_cache => true
  . . .
end
The created_by field on Rating is implemented as a "magic" field
similar to this:
2006 Sep 09
2
why doesn't this work (setting attribute in "before_create")
Hi,
Can anyone spot why the below doesn''t work?
* I have a "created_by" column in my create table in the dB
* I have a "before_create" line, which definitely gets called
* I tried a few different ways to set the "created_by" attribute in the 
model but it doesn''t seem to work, i.e. doesn''t appear in the database
2006 Apr 11
5
Multiple "has" in ActiveRecord
Please excuse a newbie question, but I couldn''t find anything by 
searching the archives.
What I want to know is how to have multiple references to the same 
class/table within a class. For example, let''s say I have a table called 
People:
create table people (
    id     serial8 primary key
   ,name);
which just holds a list of the people in the database. Then I have 
another
2006 Jan 20
11
Userstamp Plugin
I''m pleased to announce a new plugin for Rails: Userstamp. You can read my
blog post at http://www.delynnberry.com/articles/2006/01/20/userstamp-plugin
and/or read all about it at the perminant page
http://www.delynnberry.com/pages/userstamp. Any comments or suggestions for
improvement are much appreciated.
--
DeLynn Berry
delynn@gmail.com
http://www.delynnberry.com
A dump of the Readme
2006 Feb 26
3
Rails Naming Conventions
DB field names:
If I have a table that references 2 or more separate users from my users 
table, is there a recommended naming convention for this situation? In 
my case, I have 3 users associated with a record in my projects table:
  requester_user_id
  created_by
  updated_by
I could name one of them "user_id", and then projects.user would work I 
guess, but wouldn''t work
2007 May 06
5
Comparing polymorphic property to same object fails
I''ve got a polymorphic association on one table. I assign to it in the
controller.
This is handling invitations of users to tasks in a task management
application. If the user issuing the invitation is the user being
invited (ie the user assigned themselves to a task), I want to
activate the invitation immediately in the model.
The trouble is that this:
    if self.assignable ==
2006 Jan 03
2
help me understand association attributes
I have a model with a belongs_to association. The first model is called
Thing and the associated model is User. I''m attempting to assign the user to
the thing.
To accomplish this I used a before_save method, like this:
class Thing < ActiveRecord::Base
  belongs_to :created_by, :class_name => "User", :foreign_key =>
"created_by_user_id"
  def before_create
 
2006 Apr 03
3
Retrieving a record using created_by
Hello,
Thank you all in advance for your help with this.
Environment:
Windows XP Pro (Development only)
Ruby 1.84
Rails 1.1.0
SaltedHashLoginGenerator
Plugins: file_column, userstamp
I have a user table per the salted_hash_login generator. I have an 
orders table that has a column named created_by that is updated by the 
userstamp plugin. I am trying to retrieve all of the orders for a single 
2006 Jul 23
4
has_many AND has_many :through ?
Hi,
I am working on a scheduling app and I have a perpelextion (new word).
I am wondering if the problem is my data model
I have Users.
Users can create Events.
Users can be invited to Events created by other Users.
So...
user.rb
class User < ActiveRecord::Base
  has_many :invitations # invitations to other users'' events
  has_many :events, :through => :invitations # all events
2006 Sep 09
13
best way to add "created_by" entries to all tables???
Hi,
I want to automate somewhat the addition of created_by/updated_by fields 
on my models (i.e. to include username).  What''s the best/recommended 
way to do this?  Would it be to:
a) Find out how to extend the ActiveRecord::Base itself (I haven''t 
extended a class before yet)
b) Use a plugin type approach where you have to add a tag manually to 
each model file which then
2007 May 20
1
beating a dead horse - proper association selection
okay... i have two models
employee
 - id
 - username
order
 - id
 - number
 - created_by
 - approved_by
now created_by and approved_by are both id''s of employees. in most
cases, two different employees.
currently i do something like
//controller
@open_orders = Order.open_orders
//model
def self.open_orders
  find(:all, :conditions => [''is_open = ?'', true],
2006 Feb 18
5
Date formatting error
Hi All,
I''m a bit stumped.  All I''m trying to do is format a date and I get an 
error.  Details below.
I have a partial to list all "notes" associated with a "client" with the 
following code.
<% for note in @client.notes %>
<hr />
<%=h note.note_text %>
Posted on <%=h note.created_at.strftime("%I:%M") %> by <%=h 
2011 Nov 18
1
What does :count actually mean in assert_select?
Hi guys,
I tried reading up the RSPEC Book (Dec 2010) and googled a bit but  I
could not find anything.
I''m using Rspec2.
Example:
spec/factories/categories.rb
======================
FactoryGirl.define do
  factory :category_intakes, :class => ''category'' do
    name        ''intakes and filters''
    description ''airfilters and
2008 Mar 28
6
Eager Loading + Confusion
So I''m trying to do a find with an order by specific column values
thing, but some of the columns are attributes through associations.
So I did some eager loading with the :include option to try and access
the attributes of the object I''m doing the find on.  Stuff has been
blowing up on me so far.
Here''s the code in the controller right now:
sort_by = params[:sort_by]
2006 Feb 14
10
acts_as_versioned and getting authors
Hey guys and gals,
I have the following object that has acts_as_versioned:
class Note < ActiveRecord::Base
   acts_as_versioned
   belongs_to :user
end
The schema for my notes table is as follows:
     create_table :notes, :force => true do |t|
       t.column :id, :integer
       t.column :noteshare_id, :integer
       t.column :user_id, :integer
       t.column :title, :string
      
2008 Sep 25
1
question about exception
Hi
   In the controller I have the function
   def convert_sd_ticket_to_incident
    ServiceDeskTicket.close_ticket(sd_id,created_by_id,modified_by_id)
    Incident.convert_sd_ticket_to_incident(sd_id,created_by_id,modified_by_id)
   end
  Now in the ServiceDeskTicket model
  def self.close_ticket(sd_id,created_by,modified_by)
    begin
      ActiveRecord::Base.transaction do