Reputation: 1
This is the URL I want to access in my show method
http://localhost:3000/students.1
ActiveRecord::RecordNotFound in StudentsController#show Couldn't find Student with 'id'=
def show
@student = Student.find(params[:id])
my routes are
new_students GET /students/new(.:format) students#new
edit_students GET /students/edit(.:format) students#edit
students GET /students(.:format) students#show
PATCH /students(.:format) students#update
PUT /students(.:format) students#update
DELETE /students(.:format) students#destroy
POST /students(.:format) students#create
root GET / students#index
Can someone tell me how do I access that students.1 in my URL so that I can display that particular student on my show page ?
Upvotes: 0
Views: 2219
Reputation: 102443
Thats the wrong path. It should be /students/1
.
And your routes are wrong. You can tell that the routes are off by the lack of an id segment and the fact that it maps GET /students
to the show action instead of the index.
# Wrong
resource :students
# Right
resources :students
Pluralization is extremely important in Rails and is worth paying careful attention to. While its just one tiny letter these methods produce completely different routes.
resource
is for singular resources. This is not the case here.
Upvotes: 1
Reputation: 998
It should be http://localhost:3000/students/1
Check out this docs
Upvotes: 0
Reputation: 1
there is some issue with your route formation
your url is not properly forming , try below
students_path(id: student.id)
Upvotes: 0