Should be rather simple, but I can''t seem to figure it out from the API or from the tutorials. Say I have a "validates_length_of" method in one of my models and the user input is too short where an error message is generated. How (where) do I provide a placeholder for this message to appear in my view? I''ve tried "error_message_on" but keep getting an error message. Any suggestions? Steve
No takers on this? On 5/1/05, Steve Odom <steve.odom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Should be rather simple, but I can''t seem to figure it out from the > API or from the tutorials. Say I have a "validates_length_of" method > in one of my models and the user input is too short where an error > message is generated. How (where) do I provide a placeholder for this > message to appear in my view? > > I''ve tried "error_message_on" but keep getting an error message. > > Any suggestions? > > Steve >
On 5/1/05, Steve Odom <steve.odom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Should be rather simple, but I can''t seem to figure it out from the > API or from the tutorials. Say I have a "validates_length_of" method > in one of my models and the user input is too short where an error > message is generated. How (where) do I provide a placeholder for this > message to appear in my view? > > I''ve tried "error_message_on" but keep getting an error message.I think you want ''error_message_on''. If you''re using the login_generator, then you can check the signup action it creates for an example of how it works. You can also check the API reference: <http://api.rubyonrails.com/classes/ActionView/Helpers/ActiveRecordHelper.html#M000377>. Good luck. :)> SteveSincerely, Tom Reinhart tom-V0YqjHVuocLQT0dZR+AlfA@public.gmane.org http://AllTom.com/
On 5.5.2005, at 15:03, Steve Odom wrote:> No takers on this? > > On 5/1/05, Steve Odom <steve.odom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Should be rather simple, but I can''t seem to figure it out from the >> API or from the tutorials. Say I have a "validates_length_of" method >> in one of my models and the user input is too short where an error >> message is generated. How (where) do I provide a placeholder for this >> message to appear in my view?If you use script/generate scaffold to create a skeleton for your app, it will create add/edit forms that show error messages. You can take a look at them for how it is done.>> >> I''ve tried "error_message_on" but keep getting an error message.Could you elaborate a bit more? That doesn''t give much foothold for helping you. Error_message_on should be exactly what you need. //jarkko>> >> Any suggestions? >> >> Steve >> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Thanks for your help on this. This is the error message I get:
undefined method `errors'' for nil:NilClass
Here is my view:
<%= start_form_tag :action => ''add_product'' %>
<%= error_messages_for ''product'' %>
<%= text_field("new_asin", "asin") %>
<%= submit_tag "Add Product" %>
<%= end_form_tag %>
My model is:
class Product < ActiveRecord::Base
has_many :ranks
has_one :categories
validates_length_of :asin, :is=>10, :message=>"Too short."
validates_uniqueness_of :asin, :message=> "No need to add it. This
product already exists in our database."
end
I''ve tried to duplicate scaffold-created views by copying this
directly from a form partial. I''ve experimented with error_message_on.
Read the api but its proving not much help.
Any suggestions?
Steve
On 5/5/05, Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org>
wrote:> On 5.5.2005, at 15:03, Steve Odom wrote:
>
> > No takers on this?
> >
> > On 5/1/05, Steve Odom
<steve.odom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> >> Should be rather simple, but I can''t seem to figure it
out from the
> >> API or from the tutorials. Say I have a
"validates_length_of" method
> >> in one of my models and the user input is too short where an error
> >> message is generated. How (where) do I provide a placeholder for
this
> >> message to appear in my view?
>
> If you use script/generate scaffold to create a skeleton for your app,
> it will create add/edit forms that show error messages. You can take a
> look at them for how it is done.
>
> >>
> >> I''ve tried "error_message_on" but keep getting
an error message.
>
> Could you elaborate a bit more? That doesn''t give much foothold
for
> helping you. Error_message_on should be exactly what you need.
>
> //jarkko
>
> >>
> >> Any suggestions?
> >>
> >> Steve
> >>
> > _______________________________________________
> > Rails mailing list
> > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> > http://lists.rubyonrails.org/mailman/listinfo/rails
> >
> --
> Jarkko Laine
> http://jlaine.net
> http://odesign.fi
>
>
>
> My model is: > class Product < ActiveRecord::Base > has_many :ranks > has_one :categories > > validates_length_of :asin, :is=>10, :message=>"Too short." > validates_uniqueness_of :asin, :message=> "No need to add it. This > product already exists in our database." > > end > >The has_one directive is usually followed by the singular form of the name: has_one :category Is it possible that this is messing up the error messages? Duane Johnson (canadaduane)