Я прочитал много сообщений об этой проблеме, но мне так и не удалось это сделать.
Моя модель выглядит так:
class Announcement < ActiveRecord::Base
validates_presence_of :title, :description
end
Метод создания моего контроллера (только его соответствующая часть) выглядит следующим образом:
def create
respond_to do |format|
if @announcement.save
flash[:notice] = 'Announcement was successfully created.'
format.html { redirect_to(@announcement) }
format.xml { render :xml => @announcement, :status => :created, :location => @announcement }
else
@announcement = Announcement.new
@provinces = Province.all
@types = AnnouncementType.all
@categories = Tag.find_by_sql 'select * from tags where parent_id=0 order by name asc'
@subcategories= ''
format.html { render :action => "new" } #new_announcement_path
format.xml { render :xml => @announcement.errors, :status => :unprocessable_entity }
end
end
end
Моя форма выглядит так:
<% form_for(@announcement) do |f| %>
<%= error_messages_for 'announcement' %> <!--I've also treid f.error_messages-->
...
Что я делаю не так?