Displaying 20 results from an estimated 10000 matches similar to: "Database calls in my views?"
2008 Dec 09
7
subclassing vs mixins, which one should be used?
Hey all,
I have two models in my rails project that share a lot of traits. They
each have the same 4 properties, and now I need to add 2-3 methods to
each one that will be the same. In the spirit of DRY I am looking for
a solution to write these methods only once.
Both of these models already inherit from ActiveRecord . . . and I
didn''t know if it was safe to just "whip up" a
2006 Apr 21
2
accessing to a table (model)
i don''t know how to access to the collecction of data that exists in
other model.
for example
i generate two scaffold : company and employe
both have a controller, a model and 5 files in the views:
_form.rhtml, list.rhtml, new.rhtml, edit.rhtml and show.rhtml
the views are working very well, but each access just one table: company
or employe
my problem is any simple, but i
2008 Aug 24
1
avoiding exceptions in views
when rendering a view, if the object being rendered doesn''t respond to a
method it raises an error message.
For example, I have an Employee class and each employee has many Tasks.
So I may call:
<%= employee.tasks.first.task_name %>
If, for some reason an employee has 0 tasks associated with it, the
above template method would raise an exception.
Is it efficient to loop through the
2005 Dec 16
6
managing belongs_to fields in a form
Hi all,
I cannot find a clean way to create/edit an object that ''belongs_to''
another one, just by using form fields.
I always need to explicitely unassemble it, store the master id in a
hidden field, and then refetch the master from its id, and put it back
in the object.
To summarize:
I want to create a new member, for a given project
@project= ...
@member =
2007 Sep 16
4
How far to go with ActiveRecord unit tests without hitting the database?
I''m currently try to push my limits a little bit with some of my unit
testing -- trying to avoid saving ActiveRecord objects to the database and
take advantage of mock/stub objects.
How far should I expect to get in this direction? From what I can tell,
ActiveRecord seems to fight me when it comes to associations. In other
words, many associations seem to require database queries.
2007 Jul 09
3
NoMethodError when using find_by_sql
I''m try to verify users on login. Here is my code:
def self.authenticate(username,password,account_code)
employee = self.find(:all,
:select => "e.id, e.first_name, e.last_name, e.username,
e.account_id, e.department_id, o.pay_type_id, o.admin_yn, o.payroll_yn,
o.files_yn, o.dept_report_yn,e.salt, e.hashed_password",
:conditions => ["e.deleted_yn=0 and
2006 Dec 28
2
STI, controllers and views
Hello,
I have set up that uses single table inheritance. I have a number of
model subclasses following the example in AWDWR that uses Manager <
Employee < Person.
First question. Do I need to create controller classes for each? I
don''t think I do because a single controller should be able to shunt the
data between the models and the views.
Second question. Say I have a view
2006 Mar 24
7
Polymorphic associations?
I''ve read the stuff about polymorphic associations here:
http://wiki.rubyonrails.org/rails/pages/UnderstandingPolymorphicAssociations
But I''m not sure what exactly they are and what their advantage is. Are
they the same as HABTM, but they''re "two-way"?
Joe
--
Posted via http://www.ruby-forum.com/.
2006 Aug 01
2
HOWTO? security based on data values
Hi!
I recently started with RoR and this may be a newbie question.
I have a company table, employee table and transactions table.
1 company has many employees. Each employee performs many transactions.
Employees from different companies LOGIN to the system to record their
transactions. Employees can search on all transactions associated to
their companies (indirect relationship via employee),
2008 Jul 20
10
STI and fixtures
Hi all !
Loading fixtures doens''t seems to associate my 2 objects, do know what''s
wrong ?
In app/
class Manager < Employee
has_many :employees,
:foreign_key => :reports_to
end
class Employee < Person
belongs_to :manager,
:foreign_key => ''reports_to''
end
class Person < ActiveRecord::Base
belongs_to :address
end
fixtures for
2010 Jun 29
5
Samba Forum vs. Mailing List?`!
Hello everyone,
I wanted to ask if there is an official Samba Forum, because I could not
find any on the Project Page. If there isn't any, is there a particular
reason for this not-existance?
Best regards
Tom H. Lautenbacher
2007 Jan 16
2
:include with conditions.
Lets say I have an owner record which has_many employees.
If I want to eager load the employees then Owner.find(:all, :include =>
:employee) works fine and dandy.
What if I only wanted to include male employees in the eager loading for
instance? Is there an elegant and simple way to eager load with a
condition applied to the included model?
Have google and API''d around but
2006 Jul 19
11
Getting data from the database only once
Hi,
I am a little bit new to ruby. I have a requirement that I need to
get the data from the database. I need to do this many times in the
whole application. But, I am looking for a way with which I can get the
data from the database table only once and store it in some variable,
and I can use it anywhere I want.(I am trying not to use the global
variable for this purpose). Is there a way
2005 Jul 21
1
Self-Referencing Tables and Other DB Complexities
How well does Rails deal with ActiveRecord classes mapping to
self-referencing tables and other more interesting database
complexities?
i.e. Employees table with supervisor_id and mentor_id both
self-referencing Employees on the primary key "id"
or Categories table with relation table (Parent_Child_Categories) with
foreign keys parent_id and child_id both referencing Categories.id
2005 Jul 07
3
NameError Exception
Ruby/Rails n00b here so go easy on me...
I''ve been wracking my brain trying to figure out what is wrong here.
I''ve checked all my models for the appropriate belongs_to, has_many,
etc. I''ve checked to make sure I''m using singular and plurals in the
right spot. I''ve checked my syntax around all my "within"''s and nothing
seems to fix
2006 Jun 18
1
PostgreSQL Database Views with scaffold
Is there way to get the scaffold command to work with PostgreSQL
database views?
--
Posted via http://www.ruby-forum.com/.
2008 Apr 25
1
Bug#477932: logcheck-database: bind with views - messages not filtered
Package: logcheck-database
Version: 1.2.54
Severity: normal
Tags: patch
When views are used in bind, the logcheck filters don't catch the common
informational log messages.
Added regex bits to the filter definitions.
-- System Information:
Debian Release: 4.0
APT prefers stable
APT policy: (500, 'stable')
Architecture: i386 (i686)
Shell: /bin/sh linked to /bin/bash
Kernel:
2006 Mar 16
6
Newbie question - Rails without database
Hello to all,
I am entirely new to Ruby and also to Ruby on Rails. As far as I understand,
Rails builds its model according to the a specified table structuree in in the
database.
However, most of my applications, are for the most part (except some backend
CRUD stuff) not database centric. They do a lot of calculation for the user.
So, how can I create a model, when no database is needed,
2006 Feb 18
6
Naming join models
I''ve been playing around with EdgeRails and checking out some of the
new features. The one that will probably have the biggest affect on
my designs is join models (or :through associations). For those not
familiar with this feature, it lets you replace your habtm
association with a pair of has_many associations indirected through
an intermediate model class.
Looks like good
2006 Jul 17
14
REST Relationship Models
I''m trying to figure out an elegant way to do this:
I have the following three tables:
people, employer, employees
And consequently the following three models:
class Person < ActiveRecord::Base
end
class Employer < ActiveRecord::Base
has_many :employees
end
class Employee < ActiveRecord::Base
belongs_to :person
belongs_to :employer
end
I want to be able to say: