I want to count entries in this block.Because of ruby block variable scope,I don’t handle with this code.Is there any way to fix this?
arr_showcase.each do |entry|
@entry = ContestEntry.find_by_id(entry)
if @entry.view_in_showcase == true
@entry.view_in_showcase = false
@entry.save
entry_added_showcase += 1
else
@entry.view_in_showcase = true
@entry.save
entry_removed_showcase += 1
end
end
redirect_to :back, :notice => "#{entry_added_showcase} Desings added, #{entry_removed_showcase} Designs removed."
Where did you declare the
entry_added_showcaseandentry_removed_showcase? you have to initialize them outside the block.