This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Open Rails console in jruby: | |
jruby -S bundle exec rails console | |
jRuby RailsCast | |
http://railscasts.com/episodes/376-jruby-basics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% if object and object.errors.any? %> | |
<div class="error_explanation"> | |
<h2><%= pluralize(object.errors.count, "error") %> prohibited this <%= object.class.model_name.human.downcase %> from being saved:</h2> | |
<ul> | |
<% object.errors.full_messages.each do |msg| %> | |
<li>* <%= msg %></li> | |
<% end %> | |
</ul> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.icon-menu').click(function() { | |
$('.menu').animate({ | |
left: "0px" | |
}, 200); | |
$('body').animate({ | |
left: "285px" | |
}, 200); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MailersController < Admin::BaseController | |
def render_layout | |
# received params | |
# params[:mailer_type] | |
# params[:email_template] | |
# params[:email_format] | |
mailer_type = params[:mailer_type].camelize | |
mailer_template = params[:email_template] | |
type_class = mailer_type.classify.safe_constantize |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ruby function for delete leading and trailing white-spaces: | |
2.1.5 :001 > " clean up my edges ".strip | |
=> "clean up my edges" | |
Regex for trailing white-spaces: | |
[ \t]+$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def card_number_format | |
case card_type.downcase | |
when 'visa' | |
/^4\d{3}\d{4}\d{4}\d{4}$/ | |
when 'mastercard' | |
/^5[1-5]\d{2}\d{4}\d{4}\d{4}$/ | |
when 'american express' | |
/^3[4,7]\d{13}$/ | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% a = File.open("db/schema.rb") %> | |
<% a.each do |out| %> | |
<% if out.scan(/\s\s\s\st.[a-z]{1,12}\s{1,6}"(.*?)\"/) %> | |
<% if out.scan(/\s\s\s\st.[a-z]{1,12}\s{1,6}"(.*?)\"/).join(', ') == 'created_at' || out.scan(/\s\s\s\st.[a-z]{1,12}\s{1,6}"(.*?)\"/).join(', ') == 'updated_at' %> | |
<% else %> | |
:<%= out.scan(/\s\s\s\st.[a-z]{1,12}\s{1,6}"(.*?)\"/).join(', ') %>, | |
<% end %> | |
<% elsif out.scan(/\s\s\s\st.[a-z]{1,12}\s{1,6}"(.*?)\"\n\s\send/)%> | |
<% if out.scan(/\s\s\s\st.[a-z]{1,12}\s{1,6}"(.*?)\"\n\s\send/).join(', ') == 'created_at' || out.scan(/\s\s\s\st.[a-z]{1,12}\s{1,6}"(.*?)\"\n\s\send/).join(', ') == 'updated_at' %> | |
<% else %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% array_table = a.scan(/\((.*?)\ =>/) %> | |
<% array_index = a.scan(/\[(.*?)\]/) %> | |
<% com = "" %> | |
<% array_table.length.times do |element| %> | |
<% if com != array_table[element].join(', ')%> | |
<!-- Add commit --> | |
# <%= array_table[element].join(', ') %></br> | |
<% end %> | |
<!-- Text construction for output --> | |
add_index :<%= array_table[element].join(', ') %>, :<%= array_index[element].join(', ') %></br> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% link_result = Array.new([]) %> | |
<% img_result = Array.new([]) %> | |
<% require 'open-uri' %> | |
<% uri = URI.parse('http://url.com') %> | |
<% data = uri.read %> | |
<% @links = data.scan(URI.regexp(%w(http https))) %> | |
</br> | |
<% @links.each do |element| %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= text_field_tag nil, nil, :id => 'destination_name', data: {autocomplete_source: Airport.order(:name).map { |t| { :label => t.name, :value => t.id } } } %> | |
<%= text_field_tag nil, nil, :id => 'destination_id' %> | |
<script> | |
$("#destination_name").autocomplete({ | |
source:$('#destination_name').data('autocomplete-source'), | |
select: function(e, ui) { | |
e.preventDefault() // <--- Prevent the value from being inserted. | |
$(this).val(ui.item.label) | |
$('#destination_id').val(ui.item.value) | |
} |