Displaying 20 results from an estimated 500 matches similar to: "Where should I put "prerequisite logic"?"
2006 Mar 24
6
Microsoft SQL Server has me stumped
I''m tinkering around with an old legacy table in SQL Server 2000.
Ruby 1.8.4, most recent ADO.rb file from RubyForge, Rails 1.0
Here''s the model:
class InventoryItem < ActiveRecord::Base
set_table_name "[_SMDBA_].[_INVENTOR_]"
set_primary_key "sequence"
end
Everything works fine. I can retrieve records without issue.
However, when create a new
2006 Aug 15
6
try creating a table for your model
Railers:
Greetings from the low end of the learning curve. I have installed all
the prerequisites on Win32, including a lite MySQL database with a
table in it called Inventory.
Then I run this command line...
ruby script/generate ajax_scaffold Inventory
...and I get this error message:
error Before updating scaffolding from new DB schema, try creating
a table for your model
2006 Mar 15
1
An Association Problem: AR::Base.find{:include} and n-deep association traversal
Dear List,
I''m using Edge Rails.
I have a Model with Items for purchase. Each Item is of a certain brand.
Class Brand < ActiveRecord::Base
end
Class Item < ActiveRecord::Base
belongs_to :brand
end
The problem domain is that I''d like to create a separate Inventory
list of Items. This includes the date of entry into inventory and
date of exit from inventory (ie
2006 Mar 16
1
beginner question on active record relationships
say I have the following:
# user table
# - id
# - username
# - password
class User < ActiveRecord::Base
has_many :items
end
# item table
# - id
# - user_id
# - name
class Item < ActiveRecord::Base
belongs_to :user
end
What is the correct way for creating a new item instance with
relationships in place (assuming the current user is available in the
current_user instance)? Do you
2006 Apr 07
6
validation nightmare
Please help, I am really at a loss at how validation is supposed to work
in rails.
Model contains
acts_as_tree
I want to force my NEW objects to have a parent
I do NOT want existing object to have a parent
so I only want to have parent_id on create, NOT on update.
I am trying this:
def validate_on_create
validates_presence_of :parent_id, :message => "You must specify a
2011 Apr 28
3
difference between validate and validate_on_create
i just ran into a problem with some test, and i am not exactly sure why,
but the difference happened when i changed my model validation from:
validate :custom_validation
to:
validate_on_create :custom_validation
can someone give me any ideas on where in the chain the validation takes
place?
thanks!
--
Posted via http://www.ruby-forum.com/.
2006 May 04
2
validates :on 2
Hello, I need to have this for :create and :login how do I do so
validates_presence_of :login, :password, :password_confirmation,
:user_name, :email, :on => :create
I do need it to be off in a number of places though
--
Posted via http://www.ruby-forum.com/.
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
2006 Mar 16
2
Verifying existance of related record
Is there an easy way to validate that a related record exists?
I''ve got a table that contains a set of categories and I want to make
sure the user has entered a vaild category (i.e. a category that exists
in the categories table). So in the model of the table I put this:
class Master < ActiveRecord::Base
belongs_to :category, :foreign_key => "categoryid"
2006 Dec 07
2
validate_on_destroy ?
What''s the best way to validate_on_destroy. Rails only seems to include
validate_on_create and validate_on_update methods. I don''t want to
resort to doing:
before_destroy do |j|
raise "There is an error" if j.etc
end
Is there a way of finding out what action (create/update/destroy) is
being performed if I use the ''validate'' method?
--
Posted via
2006 Feb 03
2
validation only on a specific action
Hello again!
I have a action that lists users and that allows an admin user to create
new users. When the admin user creates a new user an e-mail is sent to
the created user telling him to register in the site. I want to validate
the user name and password only when the user register and not when the
admin user creates it. Can anyone tell me how to do this?
Thanks.
Best regards,
Hugo
--
2005 Dec 30
2
before_create question
I have the following models: User, Registration, Event.
User has_many Registration, Event has_many Registration, and
Registration belongs_to User and Registration. So far, so good.
There''s a registration deadline on a Event though, a few days before
the Event occurs.
So, I have this:
class Registration < AR
def before_create
errors.add_to_base("Registration deadline has
2005 Sep 27
2
No Custom Validation
Hi,
Correct me if I am wrong but there doesn''t seem to be an easy way to add
validation outside the pre-built ones (validates_presence_of,
validates_lenght_of, etc.).
Ideally there should be something like:
Class Person < ActiveRecord::Base
validates :my_method, :on => create, :message => ''was not valid''
def my_method(param)
false unless
2006 Oct 07
3
blog_id magic with typo
Hi All,
I am modifying typo so as, I can host multiple blogs on the same typo.
And its almost done, except that...i am stuck at one place.
When a user posts a new article, depending upon current blog_id, I
would like to set the blog_id attribute of @article object.
So..in the admin/content_controller.rb:
We have:
def new_or_edit
if request.post?
set_article_author
2007 Mar 28
4
Disabling ActiveRecord "type" column subclassing
Hi! I have a legacy table that has a column named "type" and need to
remove this automatic subclassing by ActiveRecord. The api pages are
vague about this, and I tried
self.inheritance_column = "xtype"
which seemed to get me half-way. In the validate_on_create method, the
value of self.type was my model Class name.
How would you disable this feature?
--
Posted via
2006 Jan 19
2
Easy way to handle form input without a model class?
I have a couple forms that I''d like to be able to validate and
automatically populate, but it shouldn''t be based on AR. In fact I
often have a bunch of small forms that I can''t really justify writing
a whole new model class for anyway. I''d like to validate the form
input, and then use rails helpers to automatically populate the form
if validations fail.
2006 Jun 19
2
call validate functions
Hi
on the code below the validates all the form fields
if @client.save
flash[:notice] = ''Client was successfully created.''
redirect_to :action => ''list''
else
render :action => ''new''
end
how can I do this action without having to save the object?
ie
if validate
#move on to next stage
else
redner
2006 Mar 02
3
validates_uniqeness_of
Hello,
I am trying to understand usage of validates_uniqeness_of.
Say I have, two column ''name'' and ''email'' in my table users
three unique key is possible for these two columns
1. name
2. email
3. name and email together
My question is,
if I write
validates_uniqueness_of :name, :email
what uniqueness is it going to apply,
1 and 2
or,
3 ?
Thanks,
Mohammad
2006 Feb 02
1
tricky form validation
Hi list,
I want to create a form validation in my Marketing Model.
I want to raise an error only if a previous marketing campaign for a
property has not been completed (ie. ended_on IS NULL)
I managed to get this working in the Controller using something this:
...
if Marketing.count("property_id = #{@marketing.property_id} AND ended_on
IS NULL") > 0
...
However I assume
2006 Feb 28
1
Validate two fields so they do not match
Hey all,
I have two form fields (select dropdowns) that are ''startlocation'' and
''endlocation''. These two cannot be equal to each other on save and I am
wondering how to put validation into the model for this. Is is possible to
do it in the model, or do I need to do this in the controller?
Thanks in advance!
Ryan
--
Ryan Prins
rprins@gmail.com