不,我不允许看其他的个人资料
我们有这样的设置:

这给我们致电users
控制器与所述URL的edit
和update
行动的能力:url.com/profile
,您将可以设置如下:
#app/controllers/users_controller.rb
class UsersController < ApplicationController
def edit
#use current_user
end
def update
redirect_to profile_path if current_user.update profile_params
end
end
#app/views/users/edit.html.erb
<%= form_for current_user do |f| %>
<%= f.text_field ....... %>
<%= f.submit %>
<% end %>
这听起来像你所需要的。
如果你想建立friendly_id
没有比较username
等,我们使用了Profile
模型,它允许您根据需要添加用户名:
#app/models/user.rb
class User < ActiveRecord::Base
has_one :profile
before_create :build_profile
delegate :name, to: :profile
end
#app/models/profile.rb
class Profile < ActiveRecord::Base
belongs_to :user
extend FriendlyId
friendly_id :name
end
然后我们管理来查找profile
有一点点黑客:
#app/controllers/users_controller.rb
class UsersController < ApplicationController
def show
@user = Profile.find(params[:id]).user #-> friendly_id looks up the :name column in users
end
end
添加用户名字段?你是否允许用户看到彼此的个人资料? –
但是,我们不需要用户的姓名日期;任何其他建议。 –
不,我不允许看到其他人的个人资料。 –