form_for不是编辑模型

时间:2011-12-19 18:47:56

标签: ruby-on-rails

我有一个Rails表单,似乎没有以任何方式更改底层对象。提交表单没有任何作用,它只是重新定向到同一页面,似乎没有做任何事情。

提交表单后,debug @booking只返回#<Booking id: nil, name: nil, email: nil, is_confirmed: false, cake_class_id: 1, created_at: nil, updated_at: nil>

_form.html.haml

= form_for @booking do |f|

  - if @booking.errors.any?
    - @booking.errors.full_messages.each do |msg|
      = msg

  = f.label :name
  = f.text_field :name
  %br
  = f.label :email
  = f.text_field :email
  %br

  = f.submit

booking_controller.rb

class BookingController < ApplicationController

  def new
    @booking = Booking.new
    @booking.is_confirmed = false
    @booking.cake_class = CakeClass.find(params[:class_id]) if CakeClass.exists?(params[:class_id])
  end

  def create
    @booking = Booking.new(params[:booking])
    if @booking.save
      redirect_to root_url
    else
      render :action => "new"
    end

  end

end

有什么建议吗?

0 个答案:

没有答案