rails表单不能用于postgresDB

时间:2015-10-13 02:22:03

标签: ruby-on-rails postgresql ruby-on-rails-4

对于我的坏英语,我向所有人道歉,无论如何我在导入数据库时​​遇到问题,我尝试将各种数据插入到PostgresDB中,但没有,有人可以帮助我吗?

预约控制器: - >

def new
    @reservation = Reservation.new
  end

  def create
    @reservation = Reservation.new(params[:reservation_params])
    if @reservation.save
      redirect_to authenticated_root_path, notice: "Registrato !!!"
    else
      render :new
    end
  end

  private
  def reservation_params
    params.require(:reservation).permit(:hotel_id, :user_id, :room_id, :room_number, :price, :channel_id)
  end

路线档案: - >

devise_for :users

  devise_scope :user do
    authenticated :user do
      root 'reservations#week', as: :authenticated_root
    end

    unauthenticated do
      root 'devise/sessions#new', as: :unauthenticated_root
    end
  end

  match '/reservations/month', to: 'reservations#month', :as => :month, via: [:get, :post]
  match '/reservations/year', to: 'reservations#year', :as => :year, via: [:get, :post]
  match '/reservations/revenue', to: 'reservations#revenue', :as => :revenue, via: [:get, :post]
  match '/reservations/future', to: 'reservations#future', :as => :future, via: [:get, :post]
  match '/reservations/event', to: 'reservations#event', :as => :event, via: [:get, :post]
  match '/reservations/new', to: 'reservations#new', :as => :new, via: [:get, :post]

  # match 'reservations/month' => 'reservations#month', :as => :reservations_month, :via => :get
  # match 'reservations/year' => 'reservations#year', :as => :reservations_year, :via => :get
  match 'hotels/dashboard' => 'hotels#dashboard', :as => :dashboard, via: [:get, :post]

预订/新文件: - >

<%= form_for @reservation do |f| %>

    <div class="input-field col s12 m2 l2">
      <%= f.label :pax %>
      <%= f.text_field :pax %>
    </div>
    <div class="input-field col s12 m2 l2">
      <%= f.label :room_number %>
      <%= f.text_field :room_number %>
    </div>
    <div class="input-field col s12 m2 l2">
      <%= f.label :price %>
      <%= f.text_field :price %>
    </div>
    <div class="input-field col s12 m2 l2">
      <%= f.label :channel_id %>
      <%= f.text_field :channel_id %>
    </div>
    <div class="input-field col s12 m2 l2">
      <%= f.submit %>
    </div>

<% end %>

2 个答案:

答案 0 :(得分:3)

更改此行:

@reservation = Reservation.new(params[:reservation_params])

为:

@reservation = Reservation.new( reservation_params )

答案 1 :(得分:0)

你在这一行中遇到了问题

@reservation = Reservation.new(params[:reservation_params])

问题是,如果你在你的控制器中看到你有一个方法只允许一些参数安全,那就是&#34; reservation_params&#34;

所以你只需要改变这个

的行
@reservation = Reservation.new(reservation_params)

它只是有效。