Rails:既给出了块arg又给出了实际块
我想在Rails 4中创建一个应用程序。
我在我的个人资料显示页面中有这个代码,以显示用户创建的所有项目。
"...", :length => 250) %>
当我尝试这个时,我得到一个错误,上面写着:
SyntaxError at /profiles/3 both block arg and actual block given
任何人都可以看到什么是错的?
方法’all_current_for_creator’在我的project.rb中定义为:
def self.all_current_for_creator(creator) if creator.profile.present? creator.current.visible else guest_visible end end
我在project.rb中定义了三个范围:
scope :creator, lambda { where(@creator_profile = user.profile_id)} scope :current, lambda { where('project.start_date >= ?', Date.today)} scope :visible, lambda { joins(:sweep => :disclosure).where('disclosures.allusers' => 'true') .joins(:sweep => :finalise).where('finalises.draft' => 'false') }
.sort_by(&:created_at) do |project|
应该:
.sort_by(&:created_at).each do |project|
因为在第一种情况下,您传递两个块&:created_at
并do ...