Rails 3: How to display error messages in embedded form? -


I am new to rail & amp; amp; This form works by itself, trying to set up my first embedded form, but I do not know how to send a verification error message to the view. I believe f.object.errors will provide access, but when the method is called in existence, f.object.errors.count always returns 0, and f.object.errors.any? In addition to displaying false return real error messages, this form is working as expected - which failed to include invalid data and returned to the form that failed verification. Models, Controllers & amp; The views listed below - Any much appreciated help

  ...  & Lt;% = form_for ([board, board board, board build]]. F | & Gt%; & Lt; Div class = "field" & gt; & Lt;% = f.label: Title% & gt; & Lt; Br / & gt; & Lt;% = f.text_field: Title% & gt; & Lt; / Div & gt; & Lt; Div class = "field" & gt; & Lt; Div class = "verb" & gt; & Lt;% = f.submit% & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt;% end% & gt; ... class boardstread & lt; ActiveRecord :: Base is_to: User is_to: Board Valid: User,: Appearance = & gt; Correct Confirmation: Board ,: Attendance = & gt; Correct confirmation: title, presence = & gt; True End Class Boardthreads Controller & lt; ApplicationController def @board = Board.find (params [: board_id]) @ boardthread = @ board.boardstread.new (param [[boardstread]) @broadthread.user = current_user_broadthread.select redirect_to board_path (@bod) and end < The reason for this is that when you're unsuccessful, you can add an object to your embedded_form Again you need to use the object with the failure in your form.  

In your new action you need to create your object and use it on your embedded form. And when you create it you use it because it is already defined

  & lt;% = form_for ([@ board, @boardthread]) do. F | & Gt%; & Lt;% @ board thread.errors.full_messages.each do | Msg | | & Gt%; & Lt; P & gt; & Lt;% = msg% & gt; & Lt; / P & gt; & Lt;% end% & gt; & Lt; Div class = "field" & gt; & Lt;% = f.label: Title% & gt; & Lt; Br / & gt; & Lt;% = f.text_field: Title% & gt; & Lt; / Div & gt; & Lt; Div class = "field" & gt; & Lt; Div class = "verb" & gt; & Lt;% = f.submit% & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt;% end% & gt;  

Comments