Reputation: 93
i am trying to create a list of leads and create a link to show each one details. so i create a controller like that :
class LeadsController < ApplicationController
def index
@leads = Leads.all
end
def show
@leads = Leads.find(params[:id])
end
def delete
end
private
def lead_params
params.require(:lead).permit(:name,:familyname,:email,:mmobile)
end
end
and a route like below :
Rails.application.routes.draw do
root 'pages#home'
get 'pages/home' => 'pages#home'
get 'leads/index'
resource :leads
get 'leads/:id/show'=> 'leads#show',:as => :leads_show end
but there are one problem and one question :
the question is when i write { Leads.find(params[:id]) }
the editor doesn't recognize params[:id] . why?
and when i want to see http://127.0.0.1:3000/leads/index i see the error like that : undefined method `lead_path' for #<#:0x36da5f8> Extracted source (around line #8):
<td><%= lead.familyname %></td>
6 <td><%= lead.mobile %></td>
7 <td><%= lead.email %></td>
8 <td><%= link_to 'show' , lead %></td>
</tr>
<% end %>
<p>Find me in app/views/leads/index.html.erb</p>
Upvotes: 0
Views: 159
Reputation: 2575
It should be
@lead = Lead.all
@lead = Lead.find(params[:id])
Model Name should be always singular, and ccontroller name will be plural
It should be resources :leads
, and it will create all the seven actions like show, update, create..etc
And you don't have to call http://127.0.0.1:3000/leads/index
this http://127.0.0.1:3000/leads
, this will call index page
Can you post your params
, so that we can see why you are not getting params[:id]
Upvotes: 1