I'm doing a cabin rental system in RoR and I get this error in the view new
of Reservations
(reservations), which gives when I try to create a form in the view. If I show the empty object that passes the controller does not throw me error, so both routes that I specify below arrive at the view and pass through the controller.
NoMethodError in Reservations # new
undefined method 'reservations_path' for # < # : 0x007f73f8791260 > Did you mean? resolve_asset_path
The view resvervations / new.html.erb is this:
<%= render 'formulario' %>
Which calls the form reservations / _formulario.html.erb :
<%= form_for(@reservation, :html => { :role => "form" }) do |f| %>
<p>
<%=f.label :tipo %>
<%=f.date_field :tipo %>
</p>
<p>
<%=f.label :description %>
<%=f.date_field :description %>
</p>
<%=f.submit %>
<% end %>
The reservations_controller.rb driver has this:
class ReservationsController < ApplicationController
def new
@reservation = Reservation.new
end
My routes.rb is the following:
Rails.application.routes.draw do
root 'cabins#index'
resources :customers, :cabins do
resource :reservations
end
get 'cabins/:id/index', to: 'reservations#index'
get ':id/new', to: 'reservations#new', as: 'new_reservation'
end
I made two paths that show new
, both are redirected from the view cabins / index , which passes @cabin
.
The relationship of the models is this:
class Customer < ApplicationRecord
has_many :reservations, :dependent => :delete_all
has_many :cabins , through: :reservations
end
class Reservation < ApplicationRecord
belongs_to :customer
belongs_to :cabin
has_one :payment
end
class Cabin < ApplicationRecord
has_many :reservations, :dependent => :delete_all
has_many :customers , through: :reservations, :dependent => :delete_all
has_many :bicycles, :dependent => :delete_all
has_many :services, :dependent => :delete_all
end
Thank you very much in advance.