Ruby on rails Rails 4,设计要发布的关联用户

Ruby on rails Rails 4,设计要发布的关联用户,ruby-on-rails,devise,ruby-on-rails-4,Ruby On Rails,Devise,Ruby On Rails 4,我已经设计好了设置,可以创建帖子,但我想添加帖子创建者的用户名。 我错过什么了吗 主计长员额: def create @post = current_member.posts.new(params[:post]) @post = Post.new(post_params) respond_to do |format| if @post.save format.html { redirect_to @post, notice: 'Post was successfully crea

我已经设计好了设置,可以创建帖子,但我想添加帖子创建者的用户名。 我错过什么了吗

主计长员额:

def create
@post = current_member.posts.new(params[:post])


@post = Post.new(post_params)
respond_to do |format|
  if @post.save
    format.html { redirect_to @post, notice: 'Post was successfully created.' }
    format.json { render action: 'show', status: :created, location: @post }
  else
    format.html { render action: 'new' }
    format.json { render json: @post.errors, status: :unprocessable_entity }
  end
end
后模型:

class Post < ActiveRecord::Base
belongs_to :member
end
class Post
成员模型:(我使用成员作为用户)

类成员
在show.html中,我不知道该在按钮上放置什么来显示用户名。我收到错误,或者在我注销之前,它只会在所有帖子上显示当前用户的电子邮件,当然是零错误

<p id="notice"><%= notice %></p>

 <p>
  <strong>Title:</strong>
  <%= @post.title %>
      </p>

  <p>
      <strong>Author:</strong>
      <%= @post.author %>
    </p>

     <p>
       <strong>Main:</strong>
     <%= @post.main %>
        </p>

           <%= current_member.email %>
          <%= link_to 'Edit', edit_post_path(@post) %> |
            <%= link_to 'Back', posts_path %>

标题:

作者:

Main:

|
我猜您不希望登录的成员/用户的电子邮件包含帖子,而是作者的电子邮件。试试:
@post.member.email

这方面运气好吗?
<p id="notice"><%= notice %></p>

 <p>
  <strong>Title:</strong>
  <%= @post.title %>
      </p>

  <p>
      <strong>Author:</strong>
      <%= @post.author %>
    </p>

     <p>
       <strong>Main:</strong>
     <%= @post.main %>
        </p>

           <%= current_member.email %>
          <%= link_to 'Edit', edit_post_path(@post) %> |
            <%= link_to 'Back', posts_path %>