简体   繁体   English

Ruby on Rails +设计

[英]Ruby on Rails + Devise

How to make public profiles with Devise? 如何使用Devise公开资料? Defaultly Devise not have public profiles. 默认情况下,Devise没有公共资料。

The best way to go about doing this is to add another controller, in this case most likely called users controller and defining a show action within that controller. 进行此操作的最佳方法是添加另一个控制器(在这种情况下,很可能称为用户控制器),并在该控制器内定义show动作。 In your routes.rb file you can define a route that sends a person seeking that user's profile to that controler action. 在routes.rb文件中,您可以定义一条路由,该路由会将寻求该用户个人资料的人员发送到该控制者操作。

It would look like this 看起来像这样

#in your routes.rb file
get '/users/:id', :to => "users#show", :as => :user

#in your users controller
class UsersController < ApplicationController
  def show
    @user = User.find(params[:id])
  end

end 

Then you obviously need to define a view that corresponds to this action in your views/users folder. 然后,您显然需要在views / users文件夹中定义一个与此操作相对应的视图。 (called show.html.erb if you use erb templates). (如果您使用erb模板,则称为show.html.erb)。

Now you can use <%= link_to(@user) do%> 现在您可以使用<%= link_to(@user)do%>

In any situation you would like to link back to this public user profile. 在任何情况下,您都想链接回此公共用户个人资料。

You could make a view that will show the user's info. 您可以创建一个显示用户信息的视图。

This view should be in one of your controllers (users controller for example) 该视图应位于您的一个控制器中(例如,用户控制器)

Grab the info in the controller from the User model, and display it in the view. 从用户模型中获取控制器中的信息,并将其显示在视图中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM