SitePoint Sponsor |
|
User Tag List
Results 1 to 16 of 16
-
Jan 25, 2008, 18:14 #1
- Join Date
- May 2007
- Posts
- 121
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
error_messages_for on Rails 2.0.2
Hello, does something change on Rails 2.0.2 about the using of error_messages_for helper ???
I have just started a new project on 2.0.2 (the first one with this Rails version) and I did, like always
app_controller
Code:def add_category @category = Category.new(params[:category]) if request.post? and @category.save flash[:notice] = 'Category successfully created' end redirect_to :action => "settings" end end
Code:<%= error_messages_for "category" %>
Thank youAlla prossima ...
-
Jan 25, 2008, 18:39 #2
- Join Date
- Apr 2006
- Location
- Uk, London
- Posts
- 228
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
that's strange, it should work.......let me have a better look on some documentation........
-
Jan 25, 2008, 18:47 #3
- Join Date
- May 2007
- Posts
- 121
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
thanks
I appreciate itAlla prossima ...
-
Jan 25, 2008, 18:54 #4
- Join Date
- Apr 2006
- Location
- Uk, London
- Posts
- 228
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
you are welcome.....
-
Jan 26, 2008, 12:06 #5
- Join Date
- May 2007
- Posts
- 121
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Did you find something about this issue ???
Thanks buddyAlla prossima ...
-
Jan 28, 2008, 07:06 #6
- Join Date
- Apr 2006
- Location
- Uk, London
- Posts
- 228
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
nope, not at the moment, sorry........
-
Jan 28, 2008, 11:51 #7
- Join Date
- May 2007
- Posts
- 121
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks buddy.
Someone else has some idea ???Alla prossima ...
-
Jan 29, 2008, 06:33 #8
- Join Date
- Apr 2006
- Location
- Uk, London
- Posts
- 228
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
no problem mate, if you want i can give u some documentation, maybe you can find the error....
-
Jan 29, 2008, 11:44 #9
- Join Date
- May 2007
- Posts
- 121
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks but I have already checked it out.
I hope someone can help me.
BYEAlla prossima ...
-
Jan 29, 2008, 18:33 #10
- Join Date
- Apr 2006
- Location
- Uk, London
- Posts
- 228
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Code:def add_category @category = Category.new(params[:category]) if request.post? and @category.save flash[:notice] = 'Category successfully created' end redirect_to :action => "settings" end end
The error_messages_for is not an error it is code that is located in your view.
Is it not working as expected?
Let me know.....
-
Jan 30, 2008, 00:54 #11
- Join Date
- May 2007
- Posts
- 121
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
There are 2 end simply because the second is the controller end.
It doesn't work at all, for instance I validate the presence of the "name" field and when I submit the form without name, the values are nor saved but no message is showed.
ThanksAlla prossima ...
-
Jan 30, 2008, 03:53 #12
- Join Date
- Feb 2006
- Location
- Worcs. UK
- Posts
- 404
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
What do you get if you put that code in the view template that contains the input form? It might also be worth trying a symbol for category rather than a string:
Code:<%= error_messages_for :category %>
-
Jan 31, 2008, 01:01 #13
- Join Date
- May 2007
- Posts
- 121
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks I tried both symbol and string with the same result: nothing is showed.
The helper is already in the same view with the form.
Code:<div class="admin_form_wrap"> <% form_for :category, :url => { :action => :add_category}, :html => { :id => "main_form"} do |form| %> <div class="element_wrap"> <span id="name"> <label for="category_name" class="mandatory_field_name">new</label> <%= form.text_field :name, :class => "text_field" %> </div> <div class="admin_button_wrap"><a class="submit_button" href="#" onclick="submitform('main_form')"><span>add</span></a></div> <% end %> </div> <div id="error"> <%= error_messages_for :category %> </div>
Alla prossima ...
-
Feb 1, 2008, 12:47 #14
- Join Date
- Apr 2006
- Location
- Uk, London
- Posts
- 228
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
In your controller, you need to tell the action to rerender the page, but your code, regardless of state always does a redirect, which means it reinitiates your object, losing your errors.
To solve it you need something like this:
Code:def add_category @category = Category.new(params[:category]) if request.post? and @category.save # here I have succeeded and can move on flash[:notice] = 'Category successfully created' redirect_to :action => "settings" else # here I rerender the page to show the errors captured in the @category object flash[:error] = 'Category could not be created' render :action => 'add_category' end end
-
Feb 1, 2008, 20:16 #15
- Join Date
- May 2007
- Posts
- 121
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
thanks buddy
I solved it 10 minutes agoAlla prossima ...
-
Feb 4, 2008, 12:48 #16
- Join Date
- Apr 2006
- Location
- Uk, London
- Posts
- 228
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
you are welcome, glad i could help...
Bookmarks