Hi,
I am sorry for maybe stupid question. I am new in rails.
I am trying to create very simple weblog systeme. I know threre are
plenty of them, but It''s good to study. I create following rule in
models/post.rb
validates_length_of :header, :in => 3..50, :allow_nil => false,
:message => "At least 3 characters"
It''s working fine with default scaffolt add form.
Then I tryed to create own new.rhtml
<?xml version="1.0" encoding="ISO-8859-2"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs"
lang="cs">
<head>
<title>Test</title>
</head>
<body>
<form action="/post/create"
method="post">
<table>
<tr>
<td>Nadpis</td>
<td><%= text_field
"post",
"header", "size" => 50, "maxlength" => 40
%></td>
</tr>
<tr>
<td>Kategorie</td>
<td>
<select
id="post_category_id" name="post[category_id]">
<%options_from_collection_for_select(@categories, ''id'',
''category'') %>
</select>
</td>
</tr>
<tr>
<td
colspan="2">Obsah</td>
</tr>
<tr>
<td
colspan="2"><%text_area("post", "value")
%></td>
</tr>
<tr>
<td
colspan="2"><%submit_tag("Save") %></td>
</tr>
</table>
</form>
</body>
</html>
when I insert correct datas it''s ok. But in case of mistake, I get
following screen
NoMethodError in Post#create
Showing /post/new.rhtml where line #18 raised undefined method
`inject'' for nil:NilClass
15: <td>Kategorie</td>
16: <td>
17: <select id="post_category_id"
name="post[category_id]">
18: <%= options_from_collection_for_select(@categories,
''id'',
''category'') %>
19: </select>
20: </td>
21: </tr>
How can I set up correct error message?
Thank you,
Michael