I put them in context, I am from Chile, and I am building a reservation engine and in the engine I need to define the current account of the clients, for that I made a list and placed it in a select and it gives me the following error undefined method `current_acounts_path' for #ActionView::Base:0x00000000024478 Did you mean? current_accounts_path
How do I solve the problem Thanks I share the codes thanks
Controller
class CurrentAccountsController < ApplicationController
before_action :authenticate_user!
def index
@currentaccounts = CurrentAcount.all
end
def new
@currentaccount = CurrentAcount.new
@clients = Client.all
end
def create
@currentacount = CurrentAcount.new(set_params)
@currentacount.client_id = @client.id
if (@currentacount.save)
redirect_to current_accounts_path, notice: "Cuenta Corriente Guardada"
else
render :new
flash.alert = "No se pudo Guardar Cuenta Corriente"
end
end
def edit
end
def update
@currentaccount.client_id = @client.id
if (@currentaccount.update(set_params))
redirect_to current_accounts_path, notice: "Modificacion de Cuenta Corriente Guardada"
else
render :edit
flash.alert = "No se pudo Modificar la Cuenta Corriente"
end
end
def show
end
def destroy
if (@currentaccount.destroy)
redirect_to current_accounts_path, notice: "Eliminada Cuenta Corriente"
else
redirect_to current_accounts_path, notice: "No se pudo Eliminar Cuenta Corriente"
end
end
private
def set_params
params.require(:current_acount).permit(:mail, :client_id, :number, :bank, :city, :telephone_contact, :type_account)
end
def set_client
@client = Client.find(params[:client_id])
end
end
Model
class CurrentAcount < ApplicationRecord
belongs_to :client
end
Form
<%= simple_form_for @currentaccount do |f| %>
<%= f.association :client, collection: @clients.map { |c| [c.name, c.id] } %>
<%= f.input :number, label: "Numero cuenta Corriente" %>
<%= f.input :type_account, prompt:"Elija tipo de cuenta", collection: ["Cuenta Correinte", "Cuenta Vista", "Cuenta de Ahorro"]%>
<%= f.input :bank, prompt:"Elija un Banco", collction: ["Banco de Chile", "Banco Internacional", "Scotiabank Chile ", "BCI", "Corpbanca", "Bnaco BICE", "HSBC Bank (Chile)", "Banco Santander-Chile", "Banco Itaú Chile", "Banco Security", "Banco Falabella", "Deutche Bank (Chile)", "Banco Ripley", "Rabobank Chile", "Banco Consorcio", "Banco Penta", "Banco Paris", "Banco Bilbao Vizcaya Argentaria, Chile (BBVA)", "Banco BTG Pactual Chile", "BancoEstado", "Banco Do Brasil S.A.", "JP MORGAN BANK, N.A.", "Banco de La Nacion Argentina", "The Bank of Tokyo-Mitsubishi UFJ, LTD"] %>
<%= f.input :city, label: "Ciudad"%>
<%= f.input :telephone_contact, label: "Telefono"%>
<%= f.input :email_contact, label: "Email"%>
<%= f.submit "Agregar" %>
<%= link_to "Volver", current_accounts_path(@reservation.client_id) %>
<% end %>
Thank for all
CodePudding user response:
Change your model to have the correct spelling. Naming needs to be consistent:
CurrentAccount # model
resources :current_accounts # routes
models/current_account.rb # filenames and
views/current_accounts/ # directories are also important.
@current_accounts # instance variables; less important,
@current_account # but why make them different.
Run a generator to get a default set up:
$ bin/rails generate scaffold_controller CurrentAccount
Just to note a few places:
@currentaccounts = CurrentAcount.all
# ^^ ^
@currentaccount = CurrentAcount.new
# ^^ ^
@currentacount = CurrentAcount.new(set_params)
# ^ ^
The actual error is coming from the form builder, because it is using CurrentAcount
model to generate a URL for the form action:
<%= simple_form_for @currentaccount do |f| %>
# which is trying to get the url
<%= url_for @currentaccount %>
# which is trying to call a named route based on the class name
# something like this:
<%= send "#{@currentaccount.model_name.route_key}_path" %>
# => undefined method `current_acounts_path'