hi all, I try to get error_message_for to get to work on my dorm. No luck... For some reason the view doesn''t show me the error message when I for example leave out the first_name Some has a clue what I''m doing wrong? Thanks, Stijn I use a helperform to create a new user: <h2>New user</h2> </form> <%= error_messages_for ''user'' %> <%= form_tag new_user_path %> <label for="user_first_name">first_name: </label><%text_field(''user'', ''first_name'') %><br/> <label for="user_last_name">last_name: </label><%text_field(''user'', ''last_name'') %><br/> <label for="user_email">email: </label><%= text_field(''user'', ''email'') %><br/> <input type="submit" value="new"> <%= end_form_tag %> the controller def new @user = User.new(params[:user]) if @user.save flash[:notice] = "Nieuwe gebruiker aangemaakt" end redirect_to :back end the model class User < ActiveRecord::Base has_and_belongs_to_many :nodes has_many :posts validates_presence_of :first_name, :last_name end --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Apparently the problem is caused by the redirect_to :back . I need to use render to preserve the errors. The problem is that I call the new method in my partial, used in different views. I thus need to redirect back. Can I use render to send me back to the previous page? Thanks, Stijn On 28 mei, 16:56, Tarscher <tarsc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hi all, > > I try to get error_message_for to get to work on my dorm. No luck... > > For some reason the view doesn''t show me the error message when I for > example leave out the first_name > > Some has a clue what I''m doing wrong? > > Thanks, > Stijn > > I use a helperform to create a new user: > <h2>New user</h2> > </form> > <%= error_messages_for ''user'' %> > <%= form_tag new_user_path %> > <label for="user_first_name">first_name: </label><%> text_field(''user'', ''first_name'') %><br/> > <label for="user_last_name">last_name: </label><%> text_field(''user'', ''last_name'') %><br/> > <label for="user_email">email: </label><%= text_field(''user'', > ''email'') %><br/> > <input type="submit" value="new"> > <%= end_form_tag %> > > the controller > def new > @user = User.new(params[:user]) > if @user.save > flash[:notice] = "Nieuwe gebruiker aangemaakt" > end > redirect_to :back > end > > the model > class User < ActiveRecord::Base > has_and_belongs_to_many :nodes > has_many :posts > validates_presence_of :first_name, :last_name > end--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
yep, i want to know that too. how use error_message_for on redirect_to action ? who''s know that? i know use flash only: def new @user = User.new(params[:user]) if @user.save flash[:notice] = "Nieuwe gebruiker aangemaakt" else flash[:error] = @user.errors.each {|field, msg| error << msg + ''<br>'' } end redirect_to :back end On 5月29日, 上午4时12分, Tarscher <tarsc...-Re5JQEeQqe8@public.gmane.orgm> wrote:> Apparently the problem is caused by the redirect_to :back . I need to > use render to preserve the errors. > > The problem is that I call the new method in my partial, used in > different views. I thus need to redirect back. Can I use render to > send me back to the previous page? > Thanks, > Stijn > > On 28 mei, 16:56, Tarscher <tarsc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > hi all, > > > I try to geterror_message_forto get to work on my dorm. No luck... > > > For some reason the view doesn''t show me the error message when I for > > example leave out the first_name > > > Some has a clue what I''m doing wrong? > > > Thanks, > > Stijn > > > I use a helperform to create a new user: > > <h2>New user</h2> > > </form> > > <%= error_messages_for ''user'' %> > > <%= form_tag new_user_path %> > > <label for="user_first_name">first_name: </label><%> > text_field(''user'', ''first_name'') %><br/> > > <label for="user_last_name">last_name: </label><%> > text_field(''user'', ''last_name'') %><br/> > > <label for="user_email">email: </label><%= text_field(''user'', > > ''email'') %><br/> > > <input type="submit" value="new"> > > <%= end_form_tag %> > > > the controller > > def new > > @user = User.new(params[:user]) > > if @user.save > > flash[:notice] = "Nieuwe gebruiker aangemaakt" > > end > > redirect_to :back > > end > > > the model > > class User < ActiveRecord::Base > > has_and_belongs_to_many :nodes > > has_many :posts > > validates_presence_of :first_name, :last_name > > end- 隐藏被引用文字 - > > - 显示引用的文字 ---~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---