我正在尝试在Rails 4中创建一个应用程序。
我在个人资料展示页面中有此代码,以显示用户创建的所有项目。
<div class="row">
<div class="col-md-10 col-md-offset-1">
<% Project.all_current_for_creator(@creator).sort_by(&:created_at) do |project| %>
<div class="row">
<div class="col-md-4">
<div class="indexdisplay">
<%= image_tag project.hero_image_url, width: '100%', height: '200px' if project.hero_image.present? %>
</div>
</div>
<div class="col-md-8">
<div class="row">
<div class="col-md-12">
<div class="indexheading"> <%= link_to project.title, project %> </div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="indexsubtext">
<%= truncate(project.description, :ommission => "...", :length => 250) %>
</div>
</div>
</div>
</div>
</div>
<% end %>
当我尝试这个时,我收到的错误是:
SyntaxError at /profiles/3
both block arg and actual block given
任何人都可以看到错误吗?
方法&#39; all_current_for_creator&#39;在我的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') }
答案 0 :(得分:2)
.sort_by(&:created_at) do |project|
应该是:
.sort_by(&:created_at).each do |project|
因为在第一种情况下,您传递了两个块&:created_at
和do ...
。