即使用户名存在,Ruby on Rails 5.2用户查找仍返回零

时间:2018-12-11 17:55:21

标签: mysql ruby-on-rails ruby-on-rails-5.2

我有两个表,一个叫User,另一个叫Colorscheme。 Colorscheme包含特定用户创建的颜色列表。在我的mysql数据库中,我用以下条目设置了用户表。

User table:
id: 1, username: bbones
id: 2, username: tomson
id: 3, username: bobjones

Colorscheme table:
id: 1, user_id: 1, title: myfirst color
id: 2, user_id: 1, title: mysecond color
id: 3, user_id: 2, title: my friends color

我遇到的问题是这一条。 somevalue = params [:user_id] 如果(somevalue)    userFound = User.find_by_field_vname(somevalue)#即使有效的用户名也返回nil。

这是我遇到问题的colorscheme助手代码。

def displayColorOwner
         value = "Colorscheme List"
         somevalue = params[:user_id]
         if(somevalue)
            userFound = User.find_by_field_vname(somevalue)
            if(userFound)
               raise "I am found"
               value = (userFound.vname + "'s colorschemes")
            else
               raise "I am not found even though: #{somevalue}"
            end
         end
         return value
      end

这是我的路由表:

Rails.application.routes.draw do

   #Pages for pouches
   resources :pouches, :only => [:index, :edit, :update]

   #Pages for colorschemes
   resources :colorschemes, :only => [:index]

   #Remember to add mute button in later
   #Pages for users
   resources :users, :except => [:new, :create] do
      resources :colorschemes, :except => [:show]
   end

   #Pages for registrations
   post 'registrations/review1', to: "registrations#approve"
   post 'registrations/review2', to: "registrations#deny"
   post 'registrations/verify', to: "registrations#verify"
   post 'registrations/gate', to: "registrations#gate"
   resources :registrations, :only => [:index, :create]

   #Pages for webcontrols
   resources :webcontrols, :only => [:index, :edit, :update]

   # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
   get 'stats', to: "start#stats"
   get 'economy', to: "start#economy"
   root "start#home"
end

有人可以帮我弄清楚为什么即使用户名存在于mysql表中,有效的用户名也被标记为nil吗?

0 个答案:

没有答案