我是新来的铁轨。在决定发布问题之前,我正在寻找答案。我找到的2个答案对我不起作用。用户名rails设备
所以我有一个模型“后”和“设计”宝石安装和配置。
然后我补充说: “用户名” 为用户
然后关系
用户 - >有很多,岗位 - >属于用户。
但我卡住了。
我该如何检索用户名以使用邮件进行呈现?
<%= post.user.username =%>?
还有什么需要做的?
post.rb
class Post < ActiveRecord::Base
attr_accessible :postbody, :posttitle
validates_presence_of :postbody, :posttitle
belongs_to :user
end
user.rb class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :username, :email, :password, :password_confirmation, :remember_me
# attr_accessible :title, :body
has_many :posts
end
请具体和描述您的问题,你有问题。 – swapab 2013-03-02 14:16:44
问题是我想呈现一个帖子已经创建的用户名。所以它会显示在文章 – igrec 2013-03-02 14:53:54