Notes posted by edivandecastro
RSS feed![Default_avatar_30](https://www.gravatar.com/avatar/b91a97f8a79bd0c29eb4e51431773aef?default=http://apidock.com/images/default_avatar_30.png&size=30)
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 }
![Default_avatar_30](https://www.gravatar.com/avatar/b91a97f8a79bd0c29eb4e51431773aef?default=http://apidock.com/images/default_avatar_30.png&size=30)
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 }
![Default_avatar_30](https://www.gravatar.com/avatar/b91a97f8a79bd0c29eb4e51431773aef?default=http://apidock.com/images/default_avatar_30.png&size=30)
Changing the Message
For Change the default message:
Code example
validates :invoice_number, :presence => {:message => 'The invoice number must be informed.'}
![Default_avatar_30](https://www.gravatar.com/avatar/b91a97f8a79bd0c29eb4e51431773aef?default=http://apidock.com/images/default_avatar_30.png&size=30)
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>
![Default_avatar_30](https://www.gravatar.com/avatar/b91a97f8a79bd0c29eb4e51431773aef?default=http://apidock.com/images/default_avatar_30.png&size=30)
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)