Hi all,
I’m new here. However, I’m so happy because I got Ruby on Rails to
work on my host. Now there’s just a problem with displaying
validation error message ,
in my view i have used the form_tag code is as follow
<% form_tag ‘create’, :multipart => true do %>
<%= error_messages_for :content_masters %>
<%= label_tag :title %>
<%= text_field_tag :title %>
content_masters is my controller name …
in my model m using
validates_presence_of(:title, :message => “message”)
the validation message is not coming …
I hope you want to help me.
Thanks
Hi Rahul,
The symbol (:content_masters) in error_messages_for should be the name
of a
variable, so if you wanted to display error messages for at variable
called
@user, you’d call it like this:
<%= error_messages_for ‘user’ %>
Please also see
http://api.rubyonrails.org/classes/ActionView/Helpers/ActiveRecordHelper.html#M001694
.
/Lasse
2010/3/27 Rahul M. [email protected]
Hi Lasse,
Thanks for your concern…
if i want to validate title than
<%= label_tag :title %>
<%= text_field_tag :title %>
then.............................
<%= error_messages_for @title %>
<%= error_messages_for :title %>
i have tried both the syntax but not working
do u have any idea …
thanks
rahul
Hi,
I think you should use error_message_on(object, method) if you want
to
show the error of one specified field, like ‘title’, ‘description’
and use error_messages_for(object) if you want to show all the
validation
errors in this object
On 27 March 2010 12:33, Rahul M. [email protected] wrote:
<%= error_messages_for :content_masters %>
the validation message is not coming …
Have a look at the rails guides at http://guides.rubyonrails.org/.
The getting started guide shows how to use form_for, which is better
than form_for in most cases, and includes display of error messages.
Also the guide on debugging shows ways of debugging your app if it is
not performing as expected. The other guides should be read also.
Colin
im also new to rails if u have good materials to learn rails please
tell me
send me links
thanks…
Hii Yong,
As i have given the syntax above would you tell me what is the syntax
i used because i have
tried so much but its not working…
thanks
rahul
Could you please paste your update code again?
<% form_tag ‘create’, :multipart => true do %>
<%= error_messages_for :content_masters %>
<%= label_tag :title %>
<%= text_field_tag :title %>
in my model m using
validates_presence_of(:title, :message => “message”)
def new
@content_master = ContentMaster.new
@metadata = @content_master.build_metadata
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @content_master }
end
end
try <%= error_messages_for :content_master %>, if content_master is
validated in your controller
if it does not work, could also please paste the code in the controller
Thanks yong the above code got worked…
thanks a lottttttttt…