Ruby

Hello guys I want to share with you about this problems with wrong color or quality for the uploaded images using Paperclip gem, Imagemagick and Heroku.com. The fix that we did it is related with the Imagemagick configuration and updates in order to fix this problem you have to do the following actions: First you have to set a new environment variables on heroku running the following command:

hello guys I want to write about selectors, overriding, and defaces in spree with the DSL for Spree: In this time I want to share the code that I have created for a simple task. The scenario is the following: I want to edit option type values in the admin section, if you take a look into the code of spree you'll see that some of the views responsible for the option type edition are located in: [shell] backend/view/spree/admin/option_types/_option_value_fields.html.erb [/shell] and [shell] backend/view/spree/admin/option_types/edit.html.erb [/shell]

Consuming Tumblr blog from your website using Ruby on Rails (Spree), Backbone and Tumblr Api You need to have an account on tumblr of course and generate the application to be able to consume the tumblr api: http://www.tumblr.com/oauth/apps About the default callback you can choose any url for example: http:://localhost:3000 Then generate the application oauth in the following url: https://api.tumblr.com/console/calls/user/info Add the following gem to your Gemfile: [ruby] gem 'tumblr_client' [/ruby]

[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]

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]

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]


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]