Hi Shelby,
No prob,
You are having trouble b/c you don''t call @festival.valid? before this
line:
if !(@festival.errors.invalid? :name ) # => true if name is invalid
I wasn''t clear about it in my post, but ActiveRecord::Errors#invalid?
doesn''t actually do validations. It just looks at the associated errors
object (which is empty if validation hasn''t been performed) to see what
errors are stored there.
Check out the api docs on this stuff @
http://api.rubyonrails.org/classes/ActiveRecord/Errors.html#M000836
http://api.rubyonrails.org/classes/ActiveRecord/Validations.html
And try firing up script/console, instantiating a Festival and setting values
for the params you expect to get, then trying the validations out, if you
haven''t already.
I don''t really know what''s up with (most of) Rails.
api.rubyonrails.org, script/console, and rgrep on my gems directory are the
1-2-3 combo punch I use to figure out what''s going on and how it works.
cheers,
phil
Shelby Westman <shelby.westman@gmail.com> wrote: Phillip - a day or so
ago, when I posted a question about validating only parts of a model, you
suggested this:
@foo = Foo.new(params[:foo])
@foo.valid? #No, cause we haven''t finished completing it yet!
@foo.errors.invalid ? :phone # => true if phone is invalid
Can you give me a little more precise information about how this is used in
code? What I would like is to have the controller method bump back to the
previous view just like it does with regular validation. I tried something like
this in my controller:
(The festival model validates_presence_of :name )
def create_festival
@festival = Festival.new
if request.post?
@festival.attributes = params[:festival] # sending in only the name at
this point...
if !(@festival.errors.invalid? :name ) # => true if name is invalid
@festival.save_with_validation(false)
@flash[:success] = "You have created a festival."
redirect_to :action => "admin_accounts_menu" and return
end
end
end
but that just seems to go ahead and save a festival with an empty name...
I''d appreciate your help.
Regards,
Shelby
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060615/e556cfca/attachment-0001.html