Skip to content

Instantly share code, notes, and snippets.

View seyhunak's full-sized avatar
🏆
Winning The Life

Seyhun Akyürek seyhunak

🏆
Winning The Life
View GitHub Profile
@seyhunak
seyhunak / simple_form.rb
Created December 14, 2011 23:17
Using simple_form and integrating Twitter Bootstrap
1. Use latest build
gem 'simple_form', :git => 'git://github.com/plataformatec/simple_form.git'
2. Create an initializer
# /config/initializers/simple_form.rb
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
# Wrappers are used by the form builder to generate a complete input.
# You can remove any component from the wrapper, change the order or even
@seyhunak
seyhunak / index.js.erb
Created December 16, 2011 23:41 — forked from ryanb/index.js.erb
Infinite scrolling solution covered in revised episode #114: http://railscasts.com/episodes/114-endless-page-revised
$('#products').append('<%= j render(@products) %>');
<% if @products.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@products) %>');
<% else %>
$('.pagination').remove();
<% end %>
@seyhunak
seyhunak / list.js
Created December 17, 2011 14:18
Searching Lists with JQuery
$(document).ready(function () {
$('#search').keyup(function(event) {
var search_text = $('#search').val();
var rg = new RegExp(search_text,'i');
$('#product_list .product-list .product').each(function(){
if($.trim($(this).html()).search(rg) == -1) {
$(this).parent().css('display', 'none');
$(this).css('display', 'none');
$(this).next().css('display', 'none');
$(this).next().next().css('display', 'none');
@seyhunak
seyhunak / gist:1499751
Created December 20, 2011 01:19 — forked from vijaydev/gist:1472145
Rails 3.2.0 Changelogs

Railties 3.2.0 (unreleased)

  • Speed up development by only reloading classes if dependencies files changed. This can be turned off by setting config.reload_classes_only_on_change to false. José Valim

  • New applications get a flag config.active_record.auto_explain_threshold_in_seconds in the environments configuration files. With a value of 0.5 in development.rb, and commented out in production.rb. No mention in test.rb. fxn

  • Add DebugExceptions middleware which contains features extracted from ShowExceptions middleware José Valim

  • Display mounted engine's routes in rake routes Piotr Sarnacki

@seyhunak
seyhunak / bootstrap_form_builder.rb
Created December 29, 2011 02:17
BootstrapFormBuilder
class BootstrapFormBuilder < ActionView::Helpers::FormBuilder
helpers = field_helpers +
%w{date_select datetime_select time_select} +
%w{collection_select select country_select time_zone_select} -
%w{hidden_field label fields_for} # Don't decorate these
helpers.each do |name|
define_method(name) do |field, *args|
options_index = ActionView::Helpers::FormBuilder.instance_method(name.to_sym).parameters.index([:opt,:options])
if options_index.nil?
options = args.last.is_a?(Hash) ? args.pop : {} # pretty sure this shouldn't happen
@seyhunak
seyhunak / _flash.html.erb
Created January 17, 2012 18:38 — forked from potomak/_flash.html.erb
Rails flash messages using Twitter bootstrap
<% [:notice, :error, :alert].each do |level| %>
<% unless flash[level].blank? %>
<div class="alert-message <%= flash_class(level) %>">
<a class="close" href="#">×</a>
<%= content_tag :p, flash[level] %>
</div>
<% end %>
<% end %>
@seyhunak
seyhunak / bootstrap_form_builder.rb
Created January 23, 2012 11:43 — forked from cbmeeks/bootstrap_form_builder.rb
Twitter Bootstrap Form Builder
class BootstrapFormBuilder < ActionView::Helpers::FormBuilder
delegate :capture, :content_tag, :tag, to: :@template
%w[text_field text_area password_field collection_select].each do |method_name|
define_method(method_name) do |name, *args|
errors = object.errors[name].any?? " error" : ""
error_msg = object.errors[name].any?? content_tag(:span, object.errors[name].join(","), class: "help-inline") : ""
content_tag :div, class: "clearfix#{errors}" do
@seyhunak
seyhunak / main_form.rb
Created January 23, 2012 11:46
Another approach to FormBuilder
# app/helpers/main_form.rb
class MainForm < ActionView::Helpers::FormBuilder # NestedForm::Builder
CSS = {
:label => 'label-control',
:hint => 'hint',
:hint_ptr => 'hint-pointer',
:error => 'help-inline',
:field_error => 'error',
:main_class => 'clearfix'
}
@seyhunak
seyhunak / Action Mailer
Created January 24, 2012 11:30 — forked from fxn/Action Mailer
Ruby on Rails v3.2.0 CHANGELOGs
## Rails 3.2.0 (January 20, 2012) ##
* Upgrade mail version to 2.4.0 *ML*
* Remove Old ActionMailer API *Josh Kalderimis*
@seyhunak
seyhunak / gist:1694192
Created January 28, 2012 12:49 — forked from mislav/gist:17371
haml2erb
class ErbEngine < Haml::Engine
def push_script(text, preserve_script, in_tag = false, preserve_tag = false,
escape_html = false, nuke_inner_whitespace = false)
push_text "<%= #{text.strip} %>"
end
def push_silent(text, can_suppress = false)
push_text "<% #{text.strip} %>"
end
end