嘿,我对 Rails 很陌生,非常感谢您的帮助!
每个用户都有一个显示他所有事件的个人资料页面。每个事件都有许多资产(图像)。每个活动也有自己的活动页面。我正在努力解决的是如何在用户个人资料页面上显示事件(如果存在)并进行加入。
在我的配置文件控制器中,我有:@events = User.joins(:events) 来获取事件,但是我需要深入到资产表中以获取相关图像(现在我只想获取任何图像)事件,稍后我将添加一个“主图片”标志)。
这是我的模型。
class Asset < ActiveRecord::Base
belongs_to :event
has_attached_file :image,
:styles => {
:thumb=> "100x100#",
:small => "300x300>",
:large => "600x600>"
},
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => ":attachment/:id/:style.:extension",
:bucket => 'wpt-assets'
end
class Event < ActiveRecord::Base
attr_accessible :name, :budget, :client, :date, :description, :venue, :attendees,
:assets_attributes
belongs_to :user
has_many :assets#, :dependent => destroy
accepts_nested_attributes_for :assets
end
class User < ActiveRecord::Base
rolify
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :role_ids, :as => :admin
attr_accessible :username, :email, :password, :password_confirmation,
:remember_me,:avatar, :bio, :title, :company,:facebook,:twitter,:pinterest,:linkedin
validates_presence_of :username
validates_uniqueness_of :username, :email, :case_sensitive => false
has_many :events
has_attached_file :avatar,
:styles => {
:medium => "100x100>",
:thumb => "24x24>" }
def to_param
username
end
end