Displaying 20 results from an estimated 12000 matches similar to: "What syntax is this? belongs_to :Person"
2005 Apr 18
11
Create a pseudo-model from SQL query?
I''m having a hard time figuring out how to build my application using Rails. As i go
along, simple questions occur to me like: are you supposed to have a separate model
class (each in its own file, in the app/models directory) for each table in your
database? You''d think that something as basic as this would be laid out in the
introductory documentation but, alas, the
2009 May 24
6
belongs_to not saving foreign key
Under Rails 2.3.2 using a completely brand new project, I have 2
models:
class Author < ActiveRecord::Base
# name:string
end
class Book < ActiveRecord::Base
# title:string
belongs_to :author # author_id
end
And a simple test where i create a Book with an Author using the
belongs_to and then update the foreign key directly:
require ''test_helper''
class BookTest
2006 Jun 19
4
share model definition
I want to share everything about a model except the db connection. Is
this a reasonable way to do it?
module NotebookDefinition
--
Posted via http://www.ruby-forum.com/.
2006 Jun 03
1
Can I tell if the associated record is new in a belongs_to save?
In a belongs_to association, is there a way to tell if the associated object
was newly created?
Hopefully this will explain my question:
A Firm class declares
has_many<http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html#M000530>:clients
and a
client class declares
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 08
21
"Rails recipes" vs "Rails cookbook"
Reviews Wanted.
I''ve read the tables of contents and haven''t yet made up my mind.
Is one book clearly better than the other? Is one clearly full of bugs? Is one so much
further ahead that there is no choice? Are they both so incomplete that I should just
wait and only cook real food? Do trains still have dining cars?
Warren Fred
-------------- next part --------------
An
2006 Mar 09
15
regular expressions slay me
I am furiously trying to find what I am looking for in Pickaxe book and
not finding it.
I''m getting some values back from a posted form and I need to get the
''id'' number off the backend. The ''String'' will always come back to me
as...
Some_name\r\n123
where 123 is actually the id number which I need to execute the find.
The reason they are coming back
2006 Mar 31
1
dumb question: what is attr_xxxx
i''m very new to the rails scene and am seeing lines of code like
attr_reader, attr_writer, attr_accessor, etc... and have no idea what
they do. reading the section in the book i''m reading that explains the
previous block of code says nothing about it really.
--
Posted via http://www.ruby-forum.com/.
2006 Feb 22
2
Newbie seeks helps ordering ancestors from acts_as_tree
I''m sure this is really obvious but I''m feeling my way here with rails
(and Ruby) and have tried a couple of things without success. So, can
anyone tell me the best way to reverse order the retuen list of
ancestors.
In the controller I have:
@ancestors = @category.ancestors
which returns an array starting at the parent and ending with the root.
When I then loop through the
2006 Jul 13
10
Book Question on RoR
Hi there,
I am a newbie and interested in learning Ruby on Rails. I see there are
2 books out there:
Ruby for Rails
Ruby techniques for Rails developers
David A. Black
and
Agile Web Development with Rails : A Pragmatic Guide (Pragmatic
Programmers)
Dave Thomas, David Heinemeier Hansson, Andreas Schwarz, and Thomas Fuchs
Which one should I get? "Agile Web Development with Rails"
2006 May 02
4
Bug in rails ?
Hi !
I just have a simple question.
I am writing an app using rails to familiarize myself with the framework (which is pretty cool, by the way).
I just wanted to know why these two work differently (since "find" should be a synonym for "detect" according to the Pick Axe) :
current_item = @invoice.line_items.detect {|i| i.product.id == key}
current_item =
2005 Apr 23
7
Validation question
Hi all,
Is there a way to invoke validations at times other than save, create
and update? I know that I can do this by writing my own validation
checks using errors.add_[blah], but I''d like to leverage the existing
validation code.
What I have is two sets of fields in a record, set A and set B. Both
sets must be validated on record create. However, the trouble is that
after
2009 Nov 18
2
Composing Data from THREE models with Aggregation
Hello! I''m looking for assistance EXTENDING an example from the Agile
Web Development With Rails book: Composing Data with Aggregation (page
324).
I''m trying to map three columns to a single Ruby object. However,
unlike the example in the Agile Web Development book, the three
columns I want to map into one object come from THREE DIFFERENT
models.
I want to map the following
2006 Nov 13
3
(A bit offtopic): A good starting book for ruby programming?
Hi all
Guess it''s time for me to dig a bit deeper into the ruby language.
Can you recommend some good starting books on ruby programming?
Thanks.
--
Med venlig hilsen
Juri Rischel Jensen
Fab:IT ApS
Vesterbrogade 50
DK-1620 København
Tlf: 70 202 407 / Fax: 33 313 640
www.fab-it.dk / juri@fab-it.dk
2007 May 21
7
How do I stop a column being updated by model.save?
One of my models has a column that is updated very frequently from a
separate process, so it is important that when a record is saved in
rails, this column should be left alone. In the update method of the
controller I have:
@record = MyModel.find(params[:id])
@record.update_attributes(params[:my_model])
params[:my_model] doesn''t have a reference to the column I''m talking
2006 Jun 06
14
How can I set the session in a functional test?
Hey :)
I need to simulate a login in my functional test, otherwise I can''t GET nor
POST to the action.
I need to set the session key "logged_in_user_id".
I tried this inside the setup() method:
session[''logged_in_user_id''] = 1
But that throws: TypeError: can''t convert String into Integer
Any ideas?
Thanks,
Rob
-------------- next part
2006 Jul 18
5
Newbie RoR question
I am currently working on a small database project to track company
assets. Right now my Database consists of 3 tables. 1 for the
equipment, 1 for the users info, and 1 for the type of equipment.
I have all 3 databases working on a model test site using RoR. Where i
am having trouble is getting the databases to talk together. I can''t
find this answer anywhere else.
My main table
2005 Dec 29
14
Rails 1.0 - Agile book still good?
I''m new to Ruby and RoR but excited to learn what I can do with RoR; I
have Pickaxe second edition and want to get "Agile Web Development with
Rails" but I''m aware that the book was published some while before RoR
version 1.0 was released. Has a lot changed since then, and would I
therefore be advised to wait for a second edition of AWDwR?
Many thanks in advance
2006 Jul 04
7
inverse of eval() ?
I''m trying to figure out how to turn a string into an object. Can anyone point me? Here''s some background.
Here''s the part of what I''m trying to do that works.
-------------------------------------
@ford = [''mustang'', ''pinto'']
make = ''@ford''
puts eval(make)
--> produces
mustang
pinto
2009 Sep 06
1
How many attributes are there of a variable?
Hi,
According to the example below this email, attr(x,"names") is the same
as names(x). I am wondering how many attributes there are of a given
variable. How to find out what they are? Can I always use
some_attribute(x) instead of attr(x, "some_attribute")?
Regards,
Peng
> x=c(1,2,3)
> attr(x,"names")=c("a","b","c")
> x
a b c