Jquery, Rails, spree / 28.03.2014

Hey there, in this time I found the following resources and how to use it using curl or ajax calls for Spree: The most of the calls need to use the "X-Spree-Token" you can generate it from admin section eg: http://localhost:3000/admin from user section and is the token you need and also you can use for example the order token, I had problems with the api using that token if you have problems let me know. Products index of products 25 first [shell]curl -i -H "X-Spree-Token: YOUR_TOKEN_ID" http://0.0.0.0:3000/api/products.json[/shell]
Rails, Ruby, spree / 26.03.2014

[ruby] namespace :banners do desc 'Populate default banners for homepage' task :populate => :environment do banner = Spree::BannerBox.find_by(category: 'box-1') unless banner 14.times do |x| box = "box-#{ x + 1 }" banner_values = { alt_text: '', url: '', category: box, banner_type: 'photo', enabled: true } banner = Spree::BannerBox.new(banner_values) banner.attachment = File.open(File.join(Rails.root, "app/assets/images/home/#{ box }.png")) banner.save! end # boxes type text 5.times do |box| box_category = "box-#{ box + 1 }-text" banner_values = { alt_text: '', url: '', banner_type: 'text', category: box_category, enabled: true } banner = Spree::BannerBox.new(banner_values) banner.attachment = File.open(File.join(Rails.root, "app/assets/images/home/#{ box_category }.png")) banner.save! end end end end [/ruby]
generales, Ruby / 19.12.2013

Hey there, Here you can find some examples using regular expression if you want to test your own regular expression you could use the following website to do it: http://rubular.com/ Regular expresion if you want for example match a exact word and that word is inside a full sentence sometimes and sometimes the first word or sometimes is the last word in the sentence you could use the following expression to get the correct matches: [ruby] ( |^)404( |$) or (^|\s)404(\s|$) [/ruby]
Ruby / 06.08.2013

Hello guys, when you are working at crowdint.com, one of the most appreciated skills in a developer is when you enjoy to refactor your code all the time and in this little example I'm will share with all of you, about how to stop or avoid using if else conditionals in Ruby, so let's start.

Before the refactor
[ruby]
class Calculator
  attr_accessor :number_one, :number_two
  def initialize number_one, number_two
    @number_one = number_one
    @number_two = number_two
  end

 def calculate
   if @number_one == 5 and @number_two == 8
     puts "Are equal to 5 and 8: #{@number_one} and #{@number_two}"
   else
     puts "Are different to 5 and 8: #{@number_one} and #{@number_two}"
   end
 end

end
calculator = Calculator.new 5, 8
calculator.calculate
[/ruby]


Rails, rspec, Ruby, Testing / 31.07.2013

My test file content: [ruby] describe ProductsService do describe '#valid?' do context 'when is successfully' do let(:result) { mock 'Result', object: {'errors' => ''}} before do subject.instance_variable_set(:@result, result) end specify do expect(subject.valid?).to be_true end end context 'when there is an error' do let(:result) { mock 'Result', object: {'errors' => 'error example'}} before do subject.instance_variable_set(:@result, result) end specify do expect(subject.valid?).to be_false end end end [/ruby]