Flowdock

Notes posted by edivandecastro

RSS feed
February 3, 2016 - (v4.0.2 - v4.2.1)
1 thank

Params of conditions

You can pass an proc for o callback with the conditions

before_action :initial_value, only: [:index, :show], unless: -> { @foo.nil? }

before_action :initial_value, only: [:index, :show], if: -> { @foo }
February 3, 2016 - (v4.0.2 - v4.2.1)
0 thanks

Params of conditions

You can pass an proc for o callback with the conditions

after_action :initial_value, only: [:index, :show], unless: -> { @foo.nil? }

after_action :initial_value, only: [:index, :show], if: -> { @foo }
July 20, 2012 - (>= v3.0.0)
2 thanks

Changing the Message

For Change the default message:

Code example

validates :invoice_number, :presence => {:message => 'The invoice number must be informed.'}
April 2, 2012
1 thank

Options select_hour

In my view I wanted to do this <%= select_hour(@hour, :start => 8, :end => 12) %> but did not work. I looked at the documentation and have not seen anything like it. http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-select_hour

So I studied how it worked this helper. http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-select_hour develop and achieve this:

the helper application:

module DataAnnouncementsHelper

class HelperDate < ActionView::Helpers::DateTimeSelector
  def select_hour
    if @options[:use_hidden] || @options[:discard_hour]
      build_hidden(:hour, hour)
    else
      build_options_and_select(:hour, hour, :end => @options[:end], :start => @options[:start], :ampm => @options[:ampm])
    end
  end
end

def select_hour(datetime, options = {}, html_options = {})
   HelperData.new(datetime, options, html_options).select_hour
end

end

The view:

<%= select_hour(@hour, :start => 8, :end => 12) %>

Where @hour = 10 the result is:

<select id=“date_hour” name=“date[hour]”>

<option value="08">08</option>
<option value="09">09</option>
<option value="10" selected="selected">10</option>
<option value="11">11</option>
<option value="12">12</option>

</select>

January 19, 2012 - (v3.0.0 - v3.1.0)
0 thanks

Options

I came across the following situation An article has a history of friendly url being that the foreign key that represents the value of the article’s id in the table is called Friend url_id then in that case:

Article.joins(“INNER JOIN friends ON articles.id = friends.url_id”).where(“friends.url like ? ”, url)

if the column url_id was renamed for artigo_id would be easier

Article.joins(:friend).where(“friends.url like ? ”, url)