简体   繁体   中英

Specify link to profile page on devise(rails)

First of all, I would like to say Im very noob on rails.

I read this question: [Public user profiles? Ruby on Rails + Devise][1]

[1]: Public user profiles? Ruby on Rails + Devise and it's working. But I can't create a link to a specific user ID.

Here is my controller:

class UsuariosController < ApplicationController
  def index
    @users = User.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @users }
    end
  end

  def show
    @user = User.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @user }
    end
  end
end

I'm using a forum gem, and in the post view file, I would like to link the 'post.user.username' ID to the link in its profile.

<span class="name"><%= link_to ".  "+post.user.username, usuarios_path, :style => "text-align: Center" %></span>

but it will go to the index, not to its ID (root/usuarios not root/usuarios/user_id)

Sorry for my english.

Just do:

<%= link_to ". #{post.user.username}", post.user %></span>

Also, keep your css from your html if possible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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