This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class InlineFormsController < ApplicationController | |
def self.cancan_enabled? | |
return @cancan_enabled if instance_variables.include?(:@cancan_enabled) | |
::Ability | |
@cancan_enabled = true | |
rescue NameError | |
@cancan_enabled = false | |
end | |
def cancan_enabled? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ree-1.8.7-2011.03 :005 > Card.new | |
=> #<Card _id: 4ec4f9ff31ef62a8ee000003> | |
ree-1.8.7-2011.03 :001 > u = User.new | |
=> #<User _id: 4ec4f9ea31ef62a8ee000001, email: nil> | |
ree-1.8.7-2011.03 :003 > u.cards | |
NoMethodError: undefined method `cards' for #<User:0x12d3170d0> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
headlines = ["one","two","three","flee"] | |
#enumerables have a method #to_phrase.rhyme_key which gives a key based on pronunciation. | |
So headlines.map(&:to_phrase.rhyme_key) => 1,2,3,3 (for example) | |
#Now I want to filter out all the strings that don't have rhyme_key counterparts, | |
essentially leaving ["three","flee"] in the convoluted example above. I tried the code below, | |
but that just stores the rhyme_key values in the headlines array which is useless to me because | |
the original string literals get replaced with the values. How do I check against the values via | |
the methods without replacing the original strings? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
begin | |
ddowns = $browser.find_elements(:css, ".n-dropdown.sizer") | |
loading = ddowns.any?{|ddown|ddown.include? 'Loading'}) | |
end while loading |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
weekdays = %w(Sun Mon Tue Wed Thu Fri Sat) | |
capture do | |
content_tag :ul do | |
weekdays.each do |day| | |
concat do | |
content_tag(:li, day) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Customer.rb | |
def self.references | |
includes(:account) | |
end | |
def self.forms | |
includes(:forms) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OtoplastikCustomer < Customer | |
def otoplastik? | |
true | |
end | |
def prices(article) | |
price_base = OtoplastikArticlePrice.where(otoplastik_article_id: article.id) | |
[id, price_group, price_list].map{|i| price_base.where(mechant_code: i)}.find(&:exists?) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/factories/users.rb | |
FactoryGirl.define do | |
sequence(:email) { |n| "user#{n}@puppa.pup" } | |
sequence(:partitaiva) { 11.times.map { (0..9).to_a.sample }.join } | |
factory :user do | |
password 'secret' | |
password_confirmation 'secret' | |
phone '0999711333' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def replacer(filename, find = ?", replace = ?') | |
File.open(filename, "r+") do |file| | |
file.each do |line| | |
file.seek(-line.bytes.to_a.size, IO::SEEK_CUR) | |
file.write line.gsub(find, replace) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
respond_to do |format| | |
format.html | |
format.xls do | |
render :xls => "some_filename", :template => "reports/#{params[:id]}.xls.writeexcel" | |
end | |
end |