RailsCasts Pro episodes are now free!

Learn more or hide this

Nick Gorbikoff's Profile

GitHub User: konung

Site: http://www.gorbikoff.com

Comments by Nick Gorbikoff

Avatar

Here is how I handle Simple_Form errors and foundation 4 ( by default I prefer to use field labels as prepends. Enjoy

ruby
  SimpleForm.setup do |config|
    config.wrappers :default, class: 'input row',
      hint_class: :field_with_hint, error_class: :errors do |b|
      b.use :html5
      b.use :placeholder
      b.optional :maxlength
      b.optional :pattern
      b.optional :min_max
      b.optional :readonly
  
      ## Inputs
      b.wrapper tag: :div, class: 'large-16 small-16 columns' do |c|
        c.wrapper tag: :div, class: 'row collapse' do |d|
          d.wrapper tag: :div, class: 'large-4 small-4 columns' do |e|
            e.use :label, wrap_with: {tag: :span, class: :prefix}
          end
          d.wrapper tag: :div, class: 'large-12 small-12 columns' do |e|
            e.use :input
          end
        end
        c.wrapper tag: :div, class: 'row collapse' do |d|
          d.wrapper tag: :div, class: 'large-16 small-16 columns' do |e|
            e.use :hint,  wrap_with: { tag: :span, class: :hint }
            e.use :error, wrap_with: { tag: :small, class: :error }
          end
        end
      end
    end
    config.default_wrapper = :default
    config.boolean_style = :nested
    config.button_class = 'button'
    config.error_notification_tag = :div
    config.error_notification_class = 'alert-box alert'
    config.label_class = 'control-label'
    config.form_class = :nice
    config.browser_validations = false
  end
Avatar

Q1

True. But for the most part it doesn't make sense from a standpoint of clarity and natural language. Let's say you have model Product and you want a service object that will handle pricing on some complex criteria (geolocation, color, shipping, moonphase, etc). It would be a good candidate for a service object ProductPricingService. You wouldn't just call it Price or Pricing. First of all it's ambigious. Pricing of what? Products that you sell? Pricing you get from vendors? Pricing of gas today? And if you were to argue that this Service object could be used by many models, then you are defeating the purpose of Service Object. I'm exaggerating of course. But the whole point is to create clear and maintainable code. So while you can save some keystrokes by naming it Price, it's much more clear to another person ( and you in 5 months) if you name it ProductPricingService.

Q2

For instance let's say you have model Product. you have methods like :

ruby
class Product < ActiveRecord::Base
  def label
    "#{self.id} - #{self.name} - #{self.description} - "
  end   
end

If this is the only method that deals with labels you have and it's that simple than creating a Service object is an overkill. However if your method becomes complex or you find that you need multiple method for related things:

ruby
class Product < ActiveRecord::Base
  def label(style="")
    if style == "full"
      "#{self.id} - #{self.name} - #{self.description} - "
    elsif style == 'short'
      "b"
    elsif style == 'russian'
      "blah2"
    else  
    end
  end   
end

You might want to move that into a service like so:

ruby
class Product < ActiveRecord::Base

  def label
    ProductLabelService.new(self)
  end  

end

class ProductLabelService
  def initialize(product)
    @product = product
  end

  def full
      "#{self.id} - #{self.name} - #{self.description} - "
  end

  def short
    "b"
  end 

  def russian
      "blah2"
  end
end  

And now just do this

    Product.first.label.full

Hope that clears things up a bit

Avatar

Ryan - first 2 layouts don't work at all of for me. divs are layered on top of each other, and it's impossible to use.

Also everything is aligned to the left ( but according to your video it should be centered). Doesn't matter how I resize my browser.

Here are screenshots of how it looks on my screen:
Skewed Layout 1
Skewed Layout 2
Skewed Layout 3

I'm using FireFox 4 on Windows XP sp3, on a 23 in monitor using 1980 x 1080 resolution.

Other than that I like new design - it's even more convenient than before.

EDIT:
Everything looks fine in latest Chrome & Safari. IE 8 seems to be ok too.