Hi,
Please Help me,in a model i gave like validates_presence_of :name,now
i
need to display error message like "name is required" while clicking
form submission button when leaving text box for name as empty,how
to do this ??

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Rafi A at Jul 20, 2012 at 10:53 am
    Manoj,

    try this in the model:

    validates_presence_of :name, :message => "can't be blank"

    Regards,
    Seeni Rafiyullah Khan A,
    Skype id: rafiyullah.railsfactory | +91 9786832092 | rafiglitz@gmail.com
    <srkhan@apigee.com>*In Every moment, thank God.*


    On Fri, Jul 20, 2012 at 4:17 PM, manoj c. wrote:

    Hi,
    Please Help me,in a model i gave like validates_presence_of :name,now
    i
    need to display error message like "name is required" while clicking
    form submission button when leaving text box for name as empty,how
    to do this ??

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups
    "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Manoj c. at Jul 23, 2012 at 4:29 am

    Rafi A wrote in post #1069463:
    Manoj,

    try this in the model:

    validates_presence_of :name, :message => "can't be blank"

    Regards,
    Seeni Rafiyullah Khan A,
    Skype id: rafiyullah.railsfactory | +91 9786832092 | rafiglitz@gmail.com
    <srkhan@apigee.com>*In Every moment, thank God.*
    Thanks a lot sir.
    regards,
    manoj

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Ace Suares at Jul 23, 2012 at 11:29 am
    Dear sirs,

    I dont't think the addition of :message => "can't be blank" does make a
    difference.\

    Validations have their own strings already packed, in en.yml in the
    active_model gem. In the console (rails c) you can try it out (assuming
    your model is named 'Person'):

    p=Person.new
    p.valid?
    p.errors
    # or p.errors[:name]

    You will see that it will show a message "can't be blank" also when you
    don't' specify :message in the validation!

    So, these messages are already generated, now you want to show them, look
    here:
    http://guides.rubyonrails.org/active_record_validations_callbacks.html#displaying-validation-errors-in-the-view
    for documentation.

    Also, <shameless plug>have a look at validation_hints gem
    (https://github.com/acesuares/validation_hints) which helps you display
    helpful context sensitive messages for form fields</shameless plug>!

    Cheers,
    ace



    On Friday, July 20, 2012 6:47:20 AM UTC-4, Ruby-Forum.com User wrote:

    Hi,
    Please Help me,in a model i gave like validates_presence_of :name,now
    i
    need to display error message like "name is required" while clicking
    form submission button when leaving text box for name as empty,how
    to do this ??

    --
    Posted via http://www.ruby-forum.com/.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/P5OKgKDw9xMJ.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Manoj c. at Jul 24, 2012 at 10:43 am

    Ace S. wrote in post #1069767:
    Dear sirs,

    I dont't think the addition of :message => "can't be blank" does make a
    difference.\

    Validations have their own strings already packed, in en.yml in the
    active_model gem. In the console (rails c) you can try it out (assuming
    your model is named 'Person'):

    p=Person.new
    p.valid?
    p.errors
    # or p.errors[:name]

    You will see that it will show a message "can't be blank" also when you
    don't' specify :message in the validation!

    So, these messages are already generated, now you want to show them,
    look
    here:
    http://guides.rubyonrails.org/active_record_validations_callbacks.html#displaying-validation-errors-in-the-view
    for documentation.

    Also, <shameless plug>have a look at validation_hints gem
    (https://github.com/acesuares/validation_hints) which helps you display
    helpful context sensitive messages for form fields</shameless plug>!

    Cheers,
    ace
    Dear ace,
    as per you have told, i wrote <%= f.error_messges %> in my
    view page to display error when leaving name as empty , but right now am
    getting like "undefined error_messages", please help me to solve this
    problem .




    regards,
    manoj

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Ace Suares at Jul 24, 2012 at 12:35 pm
    Hi manoj,

    I am replying to a message that you posted on the ruby-forum but didn't
    show up in google groups.

    Anyway, did you put

    gem "dynamic_form"



    in your Gemfile?
    And then after that, run 'bundle install' ?
    Please do so and try again.

    cheers
    ace

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/LBH6TizrmwsJ.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Manoj M. at Jul 25, 2012 at 4:30 am

    Ace S. wrote in post #1069974:
    Hi manoj,

    I am replying to a message that you posted on the ruby-forum but didn't
    show up in google groups.

    Anyway, did you put

    gem "dynamic_form"



    in your Gemfile?
    And then after that, run 'bundle install' ?
    Please do so and try again.

    cheers
    ace
    Hi ace,
    yes i did like that you told, included gem "dynamic_form" in
    gemfile and bundle install is done, but now also its not working. What
    to do next? help me.

    Regards,
    manoj

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Ace Suares at Jul 25, 2012 at 1:27 pm
    Manoj,

    Open up the console (rails c), and then create a new User (or whatever
    model you want) like this:

    u = User.new

    Check if this user is valid:

    u.valid?

    This should result in false! if NOT, then you don’t' have any errors. Then
    you have to look at you validation lines in the model...

    If it is false then try:

    u.errors
    u.errors.full_messages

    this SHOULD give you an array of error messages. If not, there's something
    wrong.

    Now go back to your view and insert

    <p>ERRORS: <%= @object.errors.full_messages %> !!! %></p>

    into your view. Of course the @object must match the one you are making the
    form for.

    Tell me what you see then.

    Cheers
    ace





    On Wednesday, July 25, 2012 12:30:14 AM UTC-4, Ruby-Forum.com User wrote:

    Ace S. wrote in post #1069974:
    Hi manoj,

    I am replying to a message that you posted on the ruby-forum but didn't
    show up in google groups.

    Anyway, did you put

    gem "dynamic_form"



    in your Gemfile?
    And then after that, run 'bundle install' ?
    Please do so and try again.

    cheers
    ace
    Hi ace,
    yes i did like that you told, included gem "dynamic_form" in
    gemfile and bundle install is done, but now also its not working. What
    to do next? help me.

    Regards,
    manoj

    --
    Posted via http://www.ruby-forum.com/.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/jDkmszj8oKoJ.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Manoj M. at Jul 26, 2012 at 5:42 am

    Ace S. wrote in post #1070147:
    Manoj,

    Open up the console (rails c), and then create a new User (or whatever
    model you want) like this:

    u = User.new

    Check if this user is valid:

    u.valid?

    This should result in false! if NOT, then you dont' have any errors.
    Then
    you have to look at you validation lines in the model...

    If it is false then try:

    u.errors
    u.errors.full_messages

    this SHOULD give you an array of error messages. If not, there's
    something
    wrong.
    Now go back to your view and insert

    <p>ERRORS: <%= @object.errors.full_messages %> !!! %></p>

    into your view. Of course the @object must match the one you are making
    the
    form for.

    Tell me what you see then.

    Cheers
    ace





    Dear ace,
    i tried with console it just works fine that showing
    error_message ["Name can't be blank"] when i gave a.errors.full_messages
    where a is a new object, but am unable to print the error message in
    view page,where only empty array is displayed, i have no idea what to
    do, its been more than 4 days i have stucked please help me out,
    expecting your help more.


    regards,
    manoj

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Vishal singh at Jul 26, 2012 at 5:54 am
    try to write this

    <% if @variable_name.errors.any? %>
    <div id="error_explanation">
    <h2><%= pluralize(@ variable_name .errors.count, "error") %>
    prohibited this user from being saved:</h2>

    <ul>
    <% @ variable_name .errors.full_messages.each do |msg| %>
    <li><%= msg %></li>
    <% end %>
    </ul>
    </div>
    <% end %>


    Regards,
    Vishal Singh





    On Thu, Jul 26, 2012 at 11:12 AM, Manoj M. wrote:

    Ace S. wrote in post #1070147:
    Manoj,

    Open up the console (rails c), and then create a new User (or whatever
    model you want) like this:

    u = User.new

    Check if this user is valid:

    u.valid?

    This should result in false! if NOT, then you dont' have any errors.
    Then
    you have to look at you validation lines in the model...

    If it is false then try:

    u.errors
    u.errors.full_messages

    this SHOULD give you an array of error messages. If not, there's
    something
    wrong.
    Now go back to your view and insert

    <p>ERRORS: <%= @object.errors.full_messages %> !!! %></p>

    into your view. Of course the @object must match the one you are making
    the
    form for.

    Tell me what you see then.

    Cheers
    ace





    Dear ace,
    i tried with console it just works fine that showing
    error_message ["Name can't be blank"] when i gave a.errors.full_messages
    where a is a new object, but am unable to print the error message in
    view page,where only empty array is displayed, i have no idea what to
    do, its been more than 4 days i have stucked please help me out,
    expecting your help more.


    regards,
    manoj

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups
    "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedJul 20, '12 at 10:47a
activeJul 26, '12 at 5:54a
posts10
users4
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase