Displaying 20 results from an estimated 47 matches for "owner_id".
Did you mean:
owner_gid
2008 Jun 13
6
Newbie question on has_many
I have two classes: a Widget and a User. The User has an id that is
referenced in two places on the Widget: owner_id and operator_id.
How should I structure that reference for has_many?
Thanks folks - I appreciate any help on this.
--David
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To po...
2006 May 14
4
searching on foreing keys
Hey all,
I''m using a simple search function. It''s working
great except for foreign keys.
I have one table pets (id,name,owner_id)
and another table people(id,name)
owner_id being a foreign key of pet pointing to people name.
here it is on the pet controller:
@paginator, @pets= paginate(:pets, :conditions =>["name OR owner_id
like ?","%"+params[:filter]+"%"], :include =>person,:order_by =&...
2008 Jul 08
4
Conditional "link_to" helper function - AYUDAME POR FAVOR
Hello,
I need to write a function that will return a link only if the current
user is the owner. Here is my code...
1. application_helper.rb
2.
3. def link_to_if_owned(owner_id, anchor_text, where_to_go)
4. if current_user.id == owner_id # current user is owner
5. "#{link_to anchor_text, where_to_go}"
6. else
7. anchor
8. end
9. end
And here''s how I call it in the view...
1. <%= link_to_if_owned(@car.owner_id, &qu...
2007 Feb 25
1
Relationships question (?)
...loping an online document editor prototype with Rails.
I am not well-versed in Rails. As a matter of fact, we chose it for the
project in order to learn it.
The problem we have is the following:
We have a User model (id, username, password, email) and we have a
Document model (id, name, content, owner_id). A document can have many
users, because we are implementing a collaboration feature, but only one
owner. The owner will have administrative rights over the document (add
collaborators, delete, etc). Users will only be able to edit the
document.
The thing is, we need a documents_users table to ha...
2005 Mar 08
1
Adding to model (newbie)
...as ''first_name'' and ''last_name'',
and I''d like to have "full_name" available.
So - models/owner.rb:
def self.full_name
first_name + '' '' + last_name
end
Then, in projects/edit.rhtml:
<p><label for="project_owner_id">Owner</label><br /><select
id="project_owner_id" name="project[owner_id]"><%=
options_from_collection_for_select @owners, "id", "full_name",
@project.owner_id %></select>
When I try to access this, I get "NoMeth...
2006 May 09
5
Shared Queue / Exclusive Query Results
My application is going to have a work queue of scheduled tasks stored
in the DB. This work queue will be shared across multiple Rails app
servers. I need a way to ensure that no two servers get the same jobs
if multiple servers pop jobs off the top of the queue simultaneously.
Is there a fairly simple way to acheive this? Or do I need to come up
with some fancy secondary server to dispatch
2010 May 14
4
Tricky model situatione
I have two models Club and users. users are regular authenticated
users and some of them might create a club. A club can also have
members (essentially users) and there are attributes and models that
apply to member but not to users.
Here is what I have right now.
Club => belongs_to :user
User => has_many clubs (since a user can host multiple clubs).
Now how do I fit this member model
2006 Apr 30
3
require "ajax_scaffold" in model error
...ght1percent.com/
articles/2006/04/18/ajaxscaffold-3-1-0-released> which suggests the
following in a model file:
--------------------------------------------------------
require ''ajax_scaffold''
class Pet < ActiveRecord::Base
belongs_to :person, :foreign_key => "owner_id"
@scaffold_columns = [
AjaxScaffold::ScaffoldColumn.new(self, { :name => "name" }),
AjaxScaffold::ScaffoldColumn.new(self, { :name => "owner",
:eval => "pet.person.name", :sort_sql => "people.name" })
]
end
--...
2006 Nov 26
5
associations help?
...jects, :through => :project_viewers, :uniq => true
...
end
class ProjectViewers < ActiveRecord::Base
belongs_to :projects
belongs_to :users
end
class Project < ActiveRecord::Base
belongs_to :owner, :class_name => ''User'', :foreign_key => ''owner_id''
has_many :project_viewers, :dependent => :destroy
has_many :users, :through => :project_viewers, :uniq => true
...
end
Things appear to work ok until I go to destroy a User, at which point I get:
../activesupport/lib/active_support/dependencies.rb:399:in
`to_const...
2006 Nov 04
0
[Markaby] select with acts_as_dropdown problem.
I''m using Markby to convert a standard form witth selects. Can someone tell
me why this works:
<tr>
<td><label class="formLabel" for="task_owner_id">Owner</label></td>
<td><%= select ''task'', ''owner_id'', Owner.to_dropdown %></td>
</tr>
But, the Markaby conversion doesn''t?
tr do
td.formLabel do label "Owner" end
td do select( '...
2006 May 29
0
using components to reuse code
...de of the controller, under the dir
components/test/:
class Test::GroupsManController < ApplicationController
uses_component_template_root
def add_to_group
@account = Account.find_by_nick(@params[:nick])
# render :text => "#{session[:account_id]}
#{Group.find(session[:group_id]).owner_id}"
if (session[:account_id] == Group.find(session[:group_id]).owner_id)
Account.join_group(@account.id, session[:group_id])
# render_component (:controller => ''test/groups_man'', :action =>
''group_list'')
group_list
else
render :partial =&...
2006 Mar 22
1
How do you clean up this cryptic code?
...dition of the associated table. There are a few
types of users, in the user_type column of the users table - owners is
type 1, users are type 2.
So in my haste to hand in enough code, in the Restaurant model, I wrote:
belongs_to :owner, :class_name => "User", :foreign_key => "owner_id",
:conditions => "user_type =1"
That worked fine. But my teammates may do something with this code.
So what I tried to do was to add a hash into the User model:
TYPE = { "user"=>2,"owner"=>1 }.freeze
But when I modified the belong_to line to
belongs_to :...
2007 Aug 17
0
map.with_options :path_prefix => ''
...put the
prefix in each individual route. Any help is appreciated.
My foo model has a polymorphic owner which is what I want the path_prefix to
represent, so my routes.rb has something like...
map.with_options :controller => ''foos'', :path_prefix =>
'':owner_type/:owner_id'' do |foos|
foos.new_foo ''/foos/new'',
:action => ''new''
foos.create_foo ''/foos'',
:action => ''create'',...
2006 Oct 13
1
Edge rails, single table inheritance and keeping multiple classes in a single file
...tions must go into separate files? I was trying to use STI with
acts_as_attachment, to have all my attachment classes go into a single
file, for example:
attachment.rb
class Attachment < ActiveRecord::Base
end
class UserPicture < Attachment
belongs_to :user, :foreign_key => ''owner_id''
acts_as_attachment ...
end
but I get the error: superclass mismatch for class UserPicture
when using "model :attachment" in my controller.. This used to work
under rails 1.1.6. I found the following bug report regarding this
problem:
http://dev.rubyonrails.org/ticket/5775...
2008 Jan 10
0
BUG? has_many :through makes funny queries
...t;
belongs_to :gallery
class User < ActiveRecord::Base
has_one :gallery, :as => :owner, :dependent => :destroy
has_many :folders, :through => :gallery
Seems fine, right? So @user.folders should do join between users,
galleries and folders.
users.id (1 in the example) == gallery.owner_id and gallery.id ==
folders.gallery_id
Right? Well it does not.
Mysql::Error: #42S22Unknown column ''galleries.gallery_id'' in ''on
clause'': SELECT folders.* FROM folders INNER JOIN galleries ON
folders.id = galleries.gallery_id WHERE ((galleries.owner_id = 1) A...
2006 Apr 24
1
Just a couple questions on how I should go about
...t/add things. Any idea how I
> should go about it?
there''s a brazillion solutions, but a good place to start might be the login
engine:
http://www.rails-engines.org/login_engine
then in your controller code you can auth against the logged-in user:
if session[:user].id == some_object.owner_id
# do stuff
end
best,
john
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
2008 Dec 20
9
Upgrade to Rails 2 - problem with "save" (MySQL boolean issue?)
I have been working through an upgrade of my 1.2.6 application to
2.2.2.
I am almost there but I have hit a problem with ActiveRecord.
Before the upgrade, the following code was working fine.
def create_root(administrator)
root = create_root_collection(self.pingee_name,
administrator,
2007 Jan 22
1
Observed models cause failures with DRBSpec ?
...ld be able to return active projects only" do
@active = mock("active")
Project.stub!(:active).and_return([@active])
@user.active_projects.should == [@active]
end
end
# app/models/user.rb
class User < ActiveRecord::Base
has_many :projects, :foreign_key => "owner_id", :order => "projects.title"
def active_projects(force=false)
@active_projects = nil if force
@active_projects ||= self.projects.active
end
end
The observer is loaded in config/environment.rb like this:
Rails::Initializer.run do |config|
config.active_record.observ...
2006 May 20
7
Polymorphic, many-to-many, self-referential data model
No matter what I try I''ve been unable to work how to get this to work with
the cool ActiveRecord helpers. I''m not sure if it''s possible, Josh Susser''s
blog suggests it is, but damned if I can work it out...
I have:
Container which can contain one or more Element. An Element is a polymorph
of either a Container or a Chunk. An Element can exist in one or more
2011 Jul 11
2
Pre-populating association
...eling:
class Survey < ActiveRecord::Base
has_many :questions
has_many :eligibilities
has_many :ballots
accepts_nested_attributes_for :questions, :allow_destroy => true
attr_accessible :title, :description, :status, :deadline, :questions_attributes
def owner
Person.find(owner_id)
end
end
class Question < ActiveRecord::Base
belongs_to :survey
has_many :preferences
end
class Ballot < ActiveRecord::Base
belongs_to :survey
has_many :preferences
end
class Preference < ActiveRecord::Base
belongs_to :ballot
belongs_to :question
end
To be clear: a survey...