Skip to content

Instantly share code, notes, and snippets.

@kibaekr
Last active December 12, 2015 01:39
Show Gist options
  • Save kibaekr/4692816 to your computer and use it in GitHub Desktop.
Save kibaekr/4692816 to your computer and use it in GitHub Desktop.
www
def achievements
achieve = []
admin_for = memberships.where(admin: true)
achieve << 'admin' if admin_for.any?
achieve << 'paid_admin' if admin_for.detect { |m| m.account.invoices.paid.any? }
#achieve << 'www' if domain_includes?("www")
achieve.join(',')
end
def domain_includes?(string)
#accounts.each { |account| account.watched_domains.each {|domain| domain.url }}.any? {|url| url.include?(string)}
accounts.each do |account|
account.watched_domains.each do |domain|
if domain.url.include?("www")
return true
else
return false
end
end
end
end
def create
@watched_domain = @current_account.watched_domains.build(params[:watched_domain])
if @watched_domain.include?("www")
@current_account.users.each { |user| user.achievements << 'www'}
end
respond_to do |format|
if @watched_domain.save
format.html { redirect_to @watched_domain, flash: { success: 'Domain was successfully created. Now try adding some keywords.' } }
format.json { render json: @watched_domain, status: :created, location: watched_domains_path }
else
format.html { redirect_to watched_domains_path, flash: { error: @watched_domain.errors[:base].join("<br />") } }
format.json { render json: @watched_domain.errors, status: :unprocessable_entity }
end
end
end
@swedler
Copy link

swedler commented Feb 1, 2013

domain_includes? method should be

def domain_includes?(string)
  all_watched_domains = user.accounts.collect{|a| a.watched_domains }.flatten
  all_watched_domains.any?{ |domain| domain.url.include?(string)}
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment