You are accessing the routes incorrectly.
To visit the index page : you need url http://localhost:3000/experiments
When you specify url : http://localhost:3000/experiments/index
, Rails would match it to the route of show page
(as shown below): /experiments/:id
If you read the error carefully:
ActiveRecord::RecordNotFound in ExperimentsController#show
Couldn't find Experiment with id=index
Rails mapped the url to show
action and is trying to find an experiment with id=index
which obviously does not exist and you get an error.
Run rake routes
on command prompt and you'll see the routes created for resource experiment
as follows:
/experiments index display a list of all experiments
GET /experiments/new new return an HTML form for creating a new experiment
POST /experiments create create a new experiment
GET /experiments/:id show display a specific experiment
GET /experiments/:id/edit edit returns an HTML form for editing an experiments
PATCH/PUT /experiments/:id update update a specific experiment
DELETE /experiments/:id destroy delete a specific experiment
You can access the specific routes with the paths shown above.
Replace :id
with an existing experiment
records id
attribute value.
For eg:
To view an experiment with id 5
Visit http://localhost:3000/experiments/5
NOTE: I would highly recommend you to go through the Rails Routing Guide and get a better idea of how Routing works.