Displaying 20 results from an estimated 10000 matches similar to: "AR model and virtual attributes"
2006 Jan 06
2
Re: Some advice on DB modeling
I have more or less the same problem. I''m trying to build a system where
users can enter their friends. But the solutions seems not to work for me.
I used same sql:
CREATE TABLE `friends` (
`user_id` int(11) NOT NULL default ''0'',
`friend_id` int(11) NOT NULL default ''0'',
KEY `user_id` (`user_id`),
KEY `friend_id` (`friend_id`),
2010 Dec 14
5
Build associated model confusion
I''m new to Rails3, and I''m just trying to get one last thing to work
before I call it a night. The situation is the following (please if
the code is horrible, just let me know, still learning):
I want to log a dive. I might have a new location on that dive at
which point I have to create a new Location, and then create the dive.
A dive has_one location. A location has_many
2006 Nov 04
0
Problems with ActiveRecord, Oracle adapter, find_by_sql, multi-table join - ORA-04043 error
Hi all,
Windows XP
Oracle 10g client
OCI8 0.1.16
Ruby 1.8.5
Rails 1.1.6
I''m hitting weird behavior with the Oracle adapter and a find_by_sql
call on a multi-table join.
The SQL looks like this:
SELECT DISTINCT e1.ip_address, loc.street, loc.city, loc.state
FROM schema.net_element ne, schema.equipment e1, schema.equipment e2,
schema.building b, schema.cust_loc cl, schema.location
2008 Jan 09
0
problem with checkboxes updating table
I''m having issues getting checkboxes to update a cross-reference table
correctly. I keep seeing entries in the locations_users table, for
location_id and user_id, "11" and "2", respectively. The user id is
fine, but there is no such location with id 11. There are only 5
locations and their ids go from 1-5! I can''t seem to find where the 11
is coming from.
2008 Jun 12
1
unidirectional belongs_to polymorphic
The setup:
class Location::Base < ActiveRecord::Base
set_table_name :locations
...
end
class Location::Address < Location::Base
...
end
class Location::Airport < Location::Base
...
end
class Person < ActiveRecord::Base
belongs_to :location, :polymorphic => true, :class_name =>
"Location::Base"
...
end
I want a unidirectional belongs_to relationship. That
2005 Dec 14
3
why would an int column in a join table be a String class in model?
i''ve got an issue with integer columns in the database becoming strings in
the model and I''m not sure why this is happening. perhaps someone can
explain.
given the following setup (simplified for example)
tables:
users
----------
id - int
name - varchar(60)
roles
----------
id - int
name - varchar(60)
roles_users (join table)
----------
role_id - int
user_id - int
2006 Apr 07
0
Custom Non-ActiveRecord Classes or not...
Say I want to gather info from various Models... Files, Folders, and put
them into a ''display'' Object DisplayFilesystem that will standarize the
info from both tables (for display only)...
Class DisplayFilesystem
attr_accessor :item_id, :name, :type, :description, :date
def initialize
@item_id = @name = @type = @description = @date = nil
end
end
So in the code side
2006 Mar 09
1
[TIP] Making an intelligent form fields
After searching arround I found a quite smart solution to me for binding
form fields to model in an active way. I use aggregations with single
value objects such as
class Percentage
attr_accessor :value
def initialize(value)
@value = (value.is_a? String) ? value.tr('' %'', '''').to_f : value
end
def to_s
return unless value
2005 Oct 14
1
Diff between attr_accessible and attr_accessor
I''m going though the paper back edition of agile development with Rails. On
page #128 I encountered following lines of code:
attr_accessor :password
attr_accessible :name,:password
What''s the difference between attr_accessor and attr_accessible?
-=- Neeraj
_______________________________________________
Rails mailing list
2008 Sep 17
2
AR: add attribute to model
Hi!
Well, I thought this was easy, but for some reason it won''t work...
Here is what I want to do:
I am working on an API to a large database. The basic mapping is done,
but I want to implement some convenience methods that take information
for one object and does some calculations with it. The result should be
accessible as attribute.
So in a simple example:
We have an object that
2010 Jun 10
1
RSpec 2: uninitialized constant - mocking belongs_to AR relation
gems/ruby-1.9.2-head/bundler/gems/rspec-
core-2398fcadf5beb256bed9c548c59445d3b4c8a047-master/lib/rspec/core/
backward_compatibility.rb:26:in `const_missing'': uninitialized
constant Message::User (NameError)
from /Users/kristianconsult/.rvm/gems/ruby-1.9.2-head/bundler/gems/
rspec-expectations-996c752171a0a0e16347e934dadc25767e31186c-master/lib/
2007 Mar 31
0
routing problem with controllers in other dirs
Hi all
I have a problem with mapping url to controller which is deeper in
controller directory (not root directory). I wanted to move
acts_as_authenticated account_controller deeper to directory (let''s
call it Foo) and route it as /Foo/Account, but i always seem to get
exception that no route matched my request
file structure:
/app
+- /controllers
+- /Foo
+-
2006 Feb 28
3
[AR] #{id} namespace visibility used in finder_sql
Dears,
[Rails 1.0.0]
I''m working with a legacy schema, and around my 20+ models i''ve used
some AR constructs.
They are based on a finder_sql doing some dirty sql and using #{id}
from the ''pivot'' model for extracting data in other tables.
like :
class Division < ActiveRecord::Base
set_table_name "legacy_division"
set_primary_key
2008 Feb 24
3
1 error(s) on assignment of multiparameter attributes
I am trying to create a form for processing credit cards. For the
credit card expiration date, I would like to leave the day field out
of the form for obvious reasons. However, the following code is
producing an error for me.
Any ideas?
Thanks!
<p><label for="email">Expiration</label><br/>
<input type="hidden" id="user_card_expiration_3i"
2008 Jun 16
2
simple rails login system
Hey All,
Just started to play around with rails a bit today by creating a
login system, but I''ve run into a glitch.
###user_controller.rb###
class UserController < ApplicationController
def login
@title = "Log In"
if request.post? and params[:user]
@user = User.new(params[:user])
@userfind =
2006 May 28
7
Self-referential has_many :through relationship
Hi,
I have a self-referential has_many :through relationship setup to
track relationships between users. Basically relationships are
modeled as a join table with an extra column ''relation''.
create table relationships (
user_id integer unsigned not null,
friend_id integer unsigned not null,
relation char(1) not null,
)
--- relations ---
f = friend
r = request to
2010 Apr 26
2
woriking under webrick but not under passenger
Hi!
I have just added login feature to my rails application (followed the
instruction from (Agile Web Development with Rails) but now I am getting
strange errors (looks to me like some kind of routing problem) under the
passenger/apache.
The error is:
500 Internal Server Error
The server encountered an internal error or misconfiguration and was
unable to complete your request.
From the log:
2006 Aug 02
2
many-to-one relationship, do I need a second table?
Ok, to keep things short. Im wondering if I need a secondary
relationship table to handle my many-to-one relationships. Here is an
example of what I''ve written down. For instance say I want to find all
of the people in a given location.
class Location < AR:Base
has_many :people
end
class Person < AR:Base
belongs_to :location
end
My SQL tables look like:
CREATE TABLE
2006 Sep 29
0
Living Dangerously?
how can I get the benefits of integration testing with Rspec on Rails
REL_0_6_3, please?
When I first started playing with Rspec on Rails, I hacked
spec_helper.rb to include the IntegrationTest interface (diff below) as
it was the minimum change I could make to get the the ability to run
multiple actions across controllers in my spec. I use it to specify
authenticated sessions and stuff.
2006 Jun 19
3
can''t dump anonymous class Class
I''m trying to create a document upload system, where most of the code is
the super class Document and just the path to file on the system is
controlled by the sub classes. When I attempt to use my code, I get the
following when I try to save the document.
can''t dump anonymous class Class
Any ideas?
** Migration **
class CreateDocuments < ActiveRecord::Migration
def