Hi I have a class ‘listings_controller’. I added a method ‘list’ in there as follows:
def index
@listings = Listing.order(:name)
end
def list
render :text=>(@listings).to_json
end
Here is my routes.rb file
root to: ‘listings#index’, as: ‘listings’
resources :listings do
collection do
get :around
end
end
match ':controller(/:action(/:id))(.:format)'
When I type this into my browser:
http://localhost:3000/listings/list
I hope to see the JSON object and its contents in the browser. However, thats not happening. I was wondering if someone could assist me in diagnosing what Im doing wrong.
The webrick server says the following:
Started GET "/listings/list" for 127.0.0.1 at 2012-04-18 11:56:25 -0700
Processing by ListingsController#show as HTML
Parameters: {"id"=>"list"}
Listing Load (0.3ms) SELECT "listings".* FROM "listings" WHERE "listings"."id" = ? LIMIT 1 [["id", "list"]]
Completed 500 Internal Server Error in 2ms
ActiveRecord::RecordNotFound (Couldn’t find Listing with id=list):
app/controllers/listings_controller.rb:104:in `show’
Add the following in your routes.rb:
match 'listings/list' => 'listings#list'Or the shorthand:
get 'listings/list'At the moment it is being routed to the show method.