Я новичок в рельсах, так что, надеюсь, это будет легко. Вот что у меня есть:
Модели / school.rb
class School < ActiveRecord::Base
has_many :courses
end
Модели / course.rb
class Course < ActiveRecord::Base
belongs_to :school
validates_presence_of :grade, :subject
end
конфиг / routes.rb
map.resources :schools, :has_many => :courses
Вид / курсы / new.html.erb
<% form_for [@school, Course.new] do |f| %>
<%= f.error_messages %>
...
<% end %>
courses_controller.rb
def create
@school = School.find(params[:school_id])
@course = @school.courses.new(params[:course])
if @course.save
flash[:notice] = 'Course was successfully created.'
redirect_to(@school)
else
respond_to do |format|
# bug: form clears and no validation error messages are displayed
format.html { render :action => "new" }
end
end
end
При сбое проверки выполняется действие new
, но значения формы очищаются, и я не вижу сообщений о сбое проверки. Чего мне не хватает?