Comment définir le chemin?Je reçois une erreur dans mon application qui est liée au chemin
je reçois l'erreur suivante lorsque je lance mon application rails:
No route matches {:action=>"show", :controller=>"practice"}, missing required keys: [:id]
Ceci est mon fichier index.erb.html
<h3>Please fill the following details</h3>
<hr>
<%= form_with scope: :welcome , local: true do |f| -%>
<b><i>Name</b></i>:            <%= f.text_field :name %> </br></br>
<b><i>Address</b></i>:         <%= f.text_area :address %> </br></br>
<b><i>City</b></i>:    <%= f.text_field :city %> </br></br>
<%= f.submit "Submit", class: "btn-submit" %>
<% end %>
Et ceci est mon routes.rb fichier.
Rails.application.routes.draw do
resources :practice
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
Ce fichier mon contrôleur:
class PracticeController < ApplicationController
def new
@welcome= Welcome.new;
end
def index
@welcome= Welcome.new;
end
def show
@welcome = Welcome.find(params[:id])
end
def create
@welcome=Welcome.new(params.require(:welcome).permit(:name,:address,:city)) ;
if @welcome.save
flash[:notice]="Successfully Registered"
redirect_to practice_path
else
flash[:notice]="Error while registering"
render:new
end
end
end
Ceci est mon fichier show.html.erb:
<p>
<strong>Name:</strong>
<%= @welcome.name %>
</p>
<p>
<strong>Address:</strong>
<%= @Welcome.address %>
</p>
<p>
\t <strong>City:</strong>
\t <%= @welcome.city%>
</p>
Je n'ai pas défini d'aide link_to pour le fichier show.html.erb.
La route # show show attend un identifiant dans les paramètres, comment faites-vous la redirection vers cette route, à travers le formulaire? un link_to helper? –
'.../practice/123'. 123 est votre identifiant de pratique. –
comment accédez-vous aux routes d'index à partir du navigateur? – Mohanraj