# Why is error not showing on rhtml page

**URL:** <https://www.ruby-forum.com/t/why-is-error-not-showing-on-rhtml-page/90560>\
**Category:** Ruby\
**Created:** [March 29, 2007, 10:43pm UTC](https://www.ruby-forum.com/t/why-is-error-not-showing-on-rhtml-page/90560 "2007-03-29T22:43:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PerfectDayToChaseTo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/898d66/32.png) [@PerfectDayToChaseTo](https://www.ruby-forum.com/u/PerfectDayToChaseTo)\
**Post date:** [March 29, 2007, 10:43pm UTC](https://www.ruby-forum.com/t/why-is-error-not-showing-on-rhtml-page/90560/1 "2007-03-29T22:43:02Z")

</div>

Hi All,

Would someone please be kind enough to help? I think I’ve got everything  
right (though obviously I havent). I am putting some validation in my  
model  
class & expecting the error to show on the page, however it isnt. When I  
submit the page with a title value, my ‘created chapter’ message appears  
&  
the chapter is persisted. If I submit without the title, validation  
fails  
(as it should), the ‘something went wrong dude’ message is shown. But  
the  
‘error\_message\_on(:chapter, :title)’ is not shown on the page. I’ve  
tried  
several things, but to no avail & I’m now tearing my (already thinning)  
hair  
out! Code follows.

chapter.rb has validates\_presence\_of :title

chapter\_controller.rb  
class ChapterController \< ApplicationController

def add\_chapter  
if request.post?  
chapter = Chapter.new(params[:chapter])  
previous\_chapter = Chapter.find(params[:previous\_chapter\_id]) if  
params[:previous\_chapter\_id]  
chapter.parent = previous\_chapter if previous\_chapter  
chapter.is\_actual = false

```
  if chapter.save
    flash[:notice] = "created chapter #{chapter.title}"
    redirect_to :action => 'add_chapter'
  else
    flash.now[:notice] = "something went wrong dude!"
  end

end

flash[:parent_id] = params[:parent_id] if params[:parent_id]

```

end

end

add\_chapter.rhtml

\<%= stylesheet\_link\_tag 'booksite', :media =\> "all" %\> \<% if flash[:notice] -%\> 
# \<%= flash[:notice] %\>
 \<% end -%\> \<% form\_for :chapter, :url =\> { :action =\> :add\_chapter } do | form |%\> 

Title \<%= form.text\_field :title, :size =\> 40 %\>**\<%= error\_message\_on(:chapter, :title) %\>**

```
    <p>
        <label for="synopsis">Synopsis</label>
        <%= form.text_area :synopsis, :rows => 20, :cols => 60 %>
    </p>

    <p>
        <label for="content">Content</label>
        <%= form.text_area :content, :rows => 30, :cols => 60 %>
    </p>
    <% if flash[:parent_id] -%>
         <%= hidden_field_tag :previous_chapter_id, 

```

flash[:parent\_id],  
:size =\> 40 %\>  
\<% end -%\>

```
    <%= submit_tag "Submit Chapter", :class => "submit" %>

<% end %>

```

Many thanks 🙂

---

<div class="post-metadata">

**Author:** ![PerfectDayToChaseTo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/898d66/32.png) [@PerfectDayToChaseTo](https://www.ruby-forum.com/u/PerfectDayToChaseTo)\
**Post date:** [March 30, 2007, 2:56pm UTC](https://www.ruby-forum.com/t/why-is-error-not-showing-on-rhtml-page/90560/2 "2007-03-30T14:56:28Z")

</div>

Where I was refereing to chapter in my controller I should have been  
refering to @chapter, d’oh! Coming from Java to Ruby, I need to get used  
to  
this 🙂
