Displaying 20 results from an estimated 1000 matches similar to: "Model Modules, Dev vs Prod"
2006 Mar 13
2
relationship woes
I have two tables:
class PgmUpdate < ActiveRecord::Base
has_many :pgm_visits, :foreign_key => ''pgm_update_fk''
...
and
class PgmVisit < ActiveRecord::Base
belongs_to :pgm_update, :foreign_key =>
''pgm_update_fk'', :dependent => true
...
According to the has_many docs (http://api.rubyonrails.org/classes/
2006 Mar 17
2
Temporary Model Data
I am trying to optimize some methods in my model so they don''t repeat
CPU intensive algorithms every time I call the method in the same
request/response cycle.
Eg.
================
def invitations
all_pgm_updates.find_all do |update|
update.invited?
end
end
================
I want to do something like:
================
def invitations
if @invitations.nil?
2006 Apr 18
1
Shared model with Capistrano/SVN
I got Capistrano working with one of my Rails projects, but I intend
to use identical models in a second project. I originally was using a
symlink to point to the other models, but I want to be able to use
the same ''rake deploy'' command for the two apps individually so I
don''t have to deploy both together all the time. Any ideas?
-John
--
John Smilanick
2006 Mar 30
1
strange has_many array problem
I have a class that has_many :visits, I want to search through the
visits to get only ones that are committed:
I thought it would be as easy as:
==================
visits.find_all do |visit|
visit.coming?
end
=================
but this always returns the entire list of visits. The only way to
get it to work is to put the visits into a new array first:
=================
2006 Mar 14
2
Two unsaved related objects
Given the two tables Parent, Child where Parent has_many children:
If I don''t save parent first then it seems that child.parent will not
be assigned automatically if I call parent.children << child . Must
the parent record be saved before I call parent.children << child ?
If I must save Parent first then can someone explain to me how I can
call parent.valid? before it
2006 Mar 14
1
Where to validate?
class PgmUpdate < ActiveRecord::Base
has_many :pgm_visits
...
class PgmVisit < ActiveRecord::Base
belongs_to :pgm_update
...
I am trying to make sure that none of the visits in PgmUpdate overlap
start and end dates. Should this validation exist in PgmUpdate or the
controller? It seems natural to put them in PgmUpdate, but I must
force the relationship together because
2006 Apr 18
1
NoMemoryError
I am using the Openbase adapter and have had a similar glitch here
and there, but after I go into production I consistently get an error
on one page.
ActionView::TemplateError (NoMemoryError: failed to allocate memory:
SELECT * FROM ...
I cannot track down the exact location of the error, but the
production log says it was around:
2006 Mar 14
7
Overriding new or create for a model
I have a model where I need to calculate one of the fields when I create
a new instance. It seems to me that I should do this in the model code
and that I should override the new and/or create methods.
Is this the right approach and, if so, how can I execute the existing
method but add on my calculation?
I want something like:
def create
-Do the original create first-
field =
2006 Mar 22
9
Display problem
hey guys,
Does anyone know why the french letter "?" is displayed as a question
mark "?" inside an <h1> tag ?
--
Posted via http://www.ruby-forum.com/.
2006 Mar 29
3
Grouping Controllers into Modules - Doesn''t work!?
Ok, what I want to achieve is:
http://<mydomain>/admin/products
calls app/controllers/admin/products_controller.rb
According to Agile Development with Rails this should work.
I executed the follwing commands:
rails myproj
cd myproj
script/generate controller Admin
script/generate scaffold Admin::Product
this creates app/controllers/admin/products_controller.rb all the views
&
2006 Mar 28
8
1.1 broke my app
I upgraded to Rails 1.1 (ruby 1.8.2 and ruby 1.8.4 on RHEL 4 using
webrick or fastcgi) and all of a sudden I get this hitting a
controller:
wrong number of arguments (1 for 0)
RAILS_ROOT: script/../config/..
Application Trace | Framework Trace |
Full Trace
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/base.rb:379:in
2006 Mar 21
8
Redirect without port number?
On my host I run my lighttpd instance bound to a specific port and my
hostname is mapped to this port (I''m not exactly sure how this is
accomplished, but it is lighttpd also listening on port 80 which handles
this for me I believe).
A redirect from rails includes my local port number in the request, so that
it shows up in the address bar. I prefer people not to see this - I
2006 Mar 14
3
Check whether externam URL is valid?
Hey,
I have users entering URLs into my app, is there anyway in which I can
check to see if the URLs actually point to something before saving the
user input? Maybe a kind of ''ping''-action that returns true on success?
(btw: does anyone of a tentative release date for Rails1.1? I''ve been
slobbering all over my RailsRecipes book and I can''t wait! Also, Scott
2006 Mar 04
5
has_many and belongs_to example?
Hi!
If i have 2 tables i.e. product and images and product has_many images,
image belongs_to product - how to create _form.rhtml, new/create and
edit/update methods in product controller, so in a single form i can add
one product and MANY (let''s assume for now that this number is fixed)
images for this product?
Pleeeeease help me :)
--
Posted via http://www.ruby-forum.com/.
2006 Mar 14
5
Unable to display errors for multiple records
Hi,
I''m trying to save multiple records of the same model in one go. Which
is no problem at all. Problem starts when I want to introduce error
handling. The problem is that no record should be saved when one of the
records contains an error. I tried it as follows:
session[:infos].each do |info|
@quest.name = info["name"]
unless @quest.valid?
@errors_found = true
2006 Apr 21
0
model modules
I have a need to subclass models a lot and I thought modules would be
the way to go, but I am encountering nothing but trouble with them. I
seem to be getting stuck with storing an object in the session, but
on the next request it can no longer read the session data and
creates a new session. Any other time I use the model it works just
fine. I read "Agile Web Development With
2006 Mar 28
0
Multiple databases & testing
Has anyone been able to get tests to work when using multiple
databases? Fixtures don''t exactly comply with the object oriented
model; it assumes they all use the same default database.
I came up with a hack for Rails 1.0, but it was a big task and I
don''t want to have to redo it for each release of Rails.
Will FlexibleFixtures support transactions for multiple databases?
2006 Mar 14
2
autocomplete using other models
I''ve asked this in various ways but I can''t seem to get much traction -
my guess is because not many people are doing this.
I am working in a controller/views called placements. Placements
belongs_to :client
I have a clients model/table - clients has_many :placements
in placements/find...this works fine...
<%= text_field_with_auto_complete :placement, :clwholename, {} %>
2006 Mar 30
1
Passing values to a Partial
Hi,
I cannot seem to find out how to pass in a value to a partial. Can
anyone help me?
What I am doing(in the code below) is calling a function in my
controller called setobject. This function just redraws the partial. I
want to be able to change the value @objectname, redraw my partial and
have it be able to use that value. The first the page is drawn it works,
but when i call setobject it
2006 Mar 29
3
Loading records during class definition
I''ve created a look-up table in my database that currently has 4
rows. I want to access these as constants in the application because
that''s effectively what they are. I tried this...
class StockRuleLevel < ActiveRecord::Base
has_many :stock_rules
SITE = find(:first, :conditions => "type_code = ''site''").id
MAKE