Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 正如我可以创建的用户名配置文件页面Rails_Ruby On Rails_Ruby On Rails 4_Devise_User Profile - Fatal编程技术网

Ruby on rails 正如我可以创建的用户名配置文件页面Rails

Ruby on rails 正如我可以创建的用户名配置文件页面Rails,ruby-on-rails,ruby-on-rails-4,devise,user-profile,Ruby On Rails,Ruby On Rails 4,Devise,User Profile,我无法找到我想要的准确信息,所以我的第二选择是提问 因此,我想知道如何从头创建一个用户配置文件,并使用您的用户名替换ID 示例:http://example.com/profile/{username} 在本例中,我对用户名没有任何问题,就像那些在游戏服务器上工作的用户名一样,它们不能包含空格或不寻常的字符 我做了一些事情,但我认为这是错误的,即使我的网站上没有任何错误 注: 我的设计模型:Player/s 玩家模式 create_table "players", force: :cas

我无法找到我想要的准确信息,所以我的第二选择是提问

因此,我想知道如何从头创建一个用户
配置文件
,并使用您的
用户名
替换
ID

示例:
http://example.com/profile/{username}
在本例中,我对用户名没有任何问题,就像那些在游戏服务器上工作的用户名一样,它们不能包含空格或不寻常的字符

我做了一些事情,但我认为这是错误的,即使我的网站上没有任何错误

注: 我的设计模型:Player/s

玩家模式

    create_table "players", force: :cascade do |t|
    t.string   "email",                  default: "",    null: false
    t.string   "encrypted_password",     default: "",    null: false
    t.string   "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.integer  "sign_in_count",          default: 0,     null: false
    t.datetime "current_sign_in_at"
    t.datetime "last_sign_in_at"
    t.string   "current_sign_in_ip"
    t.string   "last_sign_in_ip"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.boolean  "admin",                  default: false
    t.integer  "role_id"
    t.string   "nick"
    t.string   "username"
  end
变量“admin和role_id”表示网络上的费用。我认为这与主题无关

看了其他教程,但我没有更多特殊的东西添加到我的代码中

我的控制器: -注册\u controller.rb

class RegistrationsController < Devise::RegistrationsController
  protected

  def after_sign_up_path_for(resource)
    new_path(resource)
  end
end
    class ProfileController < ApplicationController
    def members
    end

    def myProfile
        @attributes = Profile.attribute_names - %w(id player_id created_at updated_at)
    end

    def new
        @profile = current_player.build_profile
    end

    def create
        @profile = current_player.build_profile(params[:profile].permit( :nick))
    end 
我希望我没有要求太多,但嘿,这是我的问题,值得一试


提前感谢,如果缺少任何内容,请告诉我。

我相信您要做的是覆盖命名的route参数。详见本导轨指南:(第4.10节)

基本上,您只需将
param::username
添加到路由文件:

resources :profile, only: [:edit], param: :username
这将使您的路线看起来像:

profile GET  /profile/:username(.:format)  profile#show
在控制器中:

@profile = Profile.find_by(username: params[:username])
希望有帮助

profile GET  /profile/:username(.:format)  profile#show
@profile = Profile.find_by(username: params[:username])