Displaying 20 results from an estimated 2000 matches similar to: "Model relationships in tests"
2007 Feb 25
1
Relationships question (?)
Hello there,
Im currently taking a Senior Design Course at my college. We are
developing 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
2006 Jun 03
8
confused about ActiveRecord relationships
I am very confused about where to put the belongs_to and the has_one
(and other relationship identifiers). I have read the RDoc and the
agile book many times about this and I think i still see it backwards.
Let me outline my app so you have an understanding...
I have 2 tables:
Schools { id, school_name, address_id }
and
Addresses { street1, street2, city, state, zip, country }
*** this
2006 Feb 08
5
beginner - problem with understanding relationships
Hi folks,
I''m new to this... so hopefully someone can help me.
I have a few objects... Property and Address and Landlord... where a
Property has an address and a landlord has an address also.
I''ve modelled this in the db with the properties table having an
address_id and the landlord table having an address id.
My rb looks like:
class Property < ActiveRecord::Base
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
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
2006 Jul 02
1
multitable form
Hi all,
Although I''m experienced with programming I''m a beginner with ruby, RoR
and MVC
So I follow examples from books and so on and all is ok.
I can make a model who is a class and who match to a table in my
database and then I generate pretty forms on a webpage.
I would like to know how I can do to make forms who interact with more
than one table.
For an example lets
2006 Feb 28
2
Need help with a Power Find()
I was hoping someone would be able to help me with creating a method.
I have two tables. What I am trying to do is create a list of all the id''s
from table2 that aren''t currently referenced by Table1''s address_id column.
That way, when I create a new customer I can have a drop down list in the
view of all the addresses that are not currently being used.
##### Database
2005 Mar 08
1
Adding to model (newbie)
Sorry if this is a really lame question, I''m sure it''s something fairly
obvious, but I just can''t see it at the moment...
I''m trying to add something simple to the model for a project
management/todo list/thing. The DB has ''first_name'' and ''last_name'',
and I''d like to have "full_name" available.
So -
2006 Feb 03
6
Saving a User Object while in the Address Controller
Hi,
My saves are failing me and I can''t figure out why.
I am trying to save an address id to a user object just after I create
the address.
This isn''t the exact code, but it shows what I am trying to do.
class AddressesController < ApplicationController
def create
@address = Address.new(params[:address])
saved_address = @address.save
@user =
2006 Aug 01
0
SEARCHING w JOIN in one-to-ma,y relationship
I am doing a Search in my ''properties'' table on column ''name'' using in
my controller :
conditions = ["name LIKE ?", "%#{@params[:query]}%"] unless
@params[:query].nil?
this ''properties'' table has a FK (owner_id) in teh column ''owner'' to
link it with the table Users...
I can display the owner.name, and
2007 Aug 17
0
map.with_options :path_prefix => ''
Hello,
I am getting a ''No route matches'' error in rspec with routes that have a
path_prefix composed by map.with_options. Rails recognizes the routes just
fine and the site works, but I can''t get the specs to pass unless I 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
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
2006 May 29
0
using components to reuse code
the following is the code 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] ==
2006 Mar 22
1
How do you clean up this cryptic code?
So, I''m coding my school project in Rails.
There are two models, User and Restaurants.
I noticed that in Restaurants, when you use the belongs_to method, you
could specify the condition 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,
2008 Jan 10
0
BUG? has_many :through makes funny queries
So I have this structure.
class Gallery < ActiveRecord::Base
belongs_to :owner, :polymorphic => true
has_many :folders, :order => ''slug'', :dependent => :destroy
class Folder < ActiveRecord::Base
has_many :photos, :dependent => :destroy, :conditions => "parent_id IS
NULL"
belongs_to :gallery
class User < ActiveRecord::Base
has_one
2009 Nov 06
0
Nested objects not propagating from view
I thought I had this fixed, but apparently not. It works okay from the
console, but not from the view. I have the following:
# partial schema
create_table "users", :force => true do |t|
t.string "login", :null => false
t.string "first_name"
t.string "last_name"
t.string "email", :null => false
2006 Jan 09
3
Design Question
I am sure some of you can give me an insight into this. This is more
towards the database design for the scenario below:
Say for example,
I have a person table and this person can have different address types.
One could be Home and the other could be say Office.
Should be model this
Table people
id
fname
lname
Table addresses
id
person_id
addr1
addr2
....
or
Table people
id
fname
lname
2006 May 17
4
NOOB: Representing linked objects in one form
Given two models:
User
:name
:email
:address_id # foreign key
Address
:line_1
:line_2
:city
etc.
I want to have a form allowing a user to register, in which she''d enter
an address as well, but how do I go about combining both objects into
the one form?
I''m new to this and following along with the Agile Rails book from the
Pragmatic Programmers, but it
2006 Jan 12
2
Can A Model Have Many belongs_to?
I am very new to Rails. After skimming through the documentation over
the last several days, I''m struggling with the appropriate use of
belongs_to. My main question is whether a model can have several
belongs_to declarations. I have not seen any examples online show that
usage. If it can, then I would like to know if it''s poor form or what
the best practices are around
2008 Sep 08
1
ActiveRecord::StatementInvalid Error
Hi There,
I''m gettings the following errors while accessing my application.
Can someone please tell what is the possible cause and can it
be resolved.
"
ActiveRecord::StatementInvalid in Site#showalladdress
Showing site/showalladdress.rhtml where line #3 raised:
Mysql::Error: #42000You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version