Sebastian Zeki
Sebastian Zeki

Reputation: 6874

Issue with routes not calling the correct page

So I always thought routes was straightforward but it clearly isn't. I want my page to show data.html.erb but it keeps on showing show.html.erb. These are my only two views in the user folder

My controller is:

 class UserController < ApplicationController

def data
  render :json =>  User.including_relationships
end

end

and my routes.rb is:

Rails.application.routes.draw do
  get 'users/:data' => 'users#data'
  resources :user
end

I always seem to get the show.html.erb page instead of the data.html.erb. Im sure there's something easy to fix here but what?

Upvotes: 0

Views: 35

Answers (1)

Sven Koschnicke
Sven Koschnicke

Reputation: 6711

The : before data in your route denotes a variable, try

Rails.application.routes.draw do
  get 'users/data' => 'users#data'
  resources :user
end

Upvotes: 4

Related Questions