I say sorry to everyone for my bad english anyway I've a problem with the rail insertion into a DB, I try in every way to insert some data into a PostgresDB but nothing, somebody can help me ?
我对每个人都说对不起我的英语不好不管怎样我的问题是把铁路插入到数据库中,我试着用各种方法把一些数据插入到PostgresDB中但是没有,有人能帮我吗?
Reservation Controller : -->
预订控制器:- - >
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
Routes file: -->
航线文件:- - >
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]
reservation/new file: -->
预订/新文件:- - >
<%= 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 个解决方案
#1
3
Change this line:
改变这条线:
@reservation = Reservation.new(params[:reservation_params])
to:
:
@reservation = Reservation.new( reservation_params )
#2
0
you have the problem in this line
这条线上有问题
@reservation = Reservation.new(params[:reservation_params])
the thing is that if you see in your controller you have a method that just permit some params for security that is "reservation_params"
如果你在你的控制器中看到你有一个方法它只允许一些安全参数的参数就是"reservation_params"
so you just need to change the line for this
你只需要改变这条线
@reservation = Reservation.new(reservation_params)
and it just works.
和它的作品。
#1
3
Change this line:
改变这条线:
@reservation = Reservation.new(params[:reservation_params])
to:
:
@reservation = Reservation.new( reservation_params )
#2
0
you have the problem in this line
这条线上有问题
@reservation = Reservation.new(params[:reservation_params])
the thing is that if you see in your controller you have a method that just permit some params for security that is "reservation_params"
如果你在你的控制器中看到你有一个方法它只允许一些安全参数的参数就是"reservation_params"
so you just need to change the line for this
你只需要改变这条线
@reservation = Reservation.new(reservation_params)
and it just works.
和它的作品。