Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

routes.rb - Controller name not supported

I'm having quite a peculiar issue. This is the portion of routes.rb it relates to:

resources :players
match '/players/:userid', :to => 'Players#show'

When you visit localhost:3000/players/1234 it gives this error:

'Players' is not a supported controller name. This can lead to potential routing problems.

The related code in the controller:

def show
  begin
    if Player.find_by(:uid => :userid) then
      @playerattributes = Player.find_by(:uid => :userid) 
      if player[:profile_complete] == true then
        @playerinfo = {
            :age => player[:age],
            :team => player[:team],
            :position => player[:position]
        }
      else
        @playerinfo = 0 
      end
    end
    player = Player.find_by(:uid => :userid)[:info]
rescue ActiveRecord::RecordNotFound
    redirect_to root_url        
    end
end

The problem doesn't end there. When the page does load (which it sometimes randomly works), this line acts up: if Player.find_by(:uid => :userid) then Using PostgreSQL, and the query gets displayed. Instead of using the :userid value from the URL (i.e. localhost:3000/players/1234 would be 1234), it just inputs the text "userid".

Am I missing something obvious?

Really appreciate any help.

like image 215
Nick Avatar asked Mar 27 '14 18:03

Nick


2 Answers

Change: Players to players so:

match '/players/:userid', :to => 'Players#show'

to

match '/players/:userid', :to => 'players#show'

Read more.

To read user id value in your controller, use params[:userid], not just :userid.

like image 143
Lenin Raj Rajasekaran Avatar answered Nov 03 '22 11:11

Lenin Raj Rajasekaran


Rails individual routes is going to write in this way.

EG: requested action "browser url_name(whatever you want)", to:

'controller_name#method_name'

In your case it should be:

match  '/players/:userid', :to => 'players#show'

Similarly for a get request:

get  '/players/:userid', :to => 'players#show'
like image 2
Anupam Avatar answered Nov 03 '22 10:11

Anupam