rocky
rocky

Reputation: 45

Adding a webpage in rails for model

I need to add a graph page such that when 'listing/id/graph' is clicked, the graph page of listing id is rendered. This graph page contains analytics of that listing id.

I tried the following:

adding in routes.rb get 'graphs' => "listings#id#graphs"

listings controller 
 def graphs
    @listing = Listing.find(params[:id])
  end
as same as 
def show
           @listing = Listing.find(params[:id])
 end

Current result: No route matches [GET] "/listings/2/graphs"

Expected result: render graphs.html.erb

Rake routes rake routes

I'm pretty new to Ruby-on-Rails. Thanks in advance.

Upvotes: 0

Views: 63

Answers (1)

Veridian Dynamics
Veridian Dynamics

Reputation: 1406

The answer is obvious. You don't have a route like: listings/:id/graph and you want that to exist. Create that route.

  get '/listings/:id/graphs' => 'listings#graphs'

This will be tedious, but it'll benefit you greatly to read through this https://guides.rubyonrails.org/routing.html before moving forward.

Upvotes: 1

Related Questions