Skip to content

Instantly share code, notes, and snippets.

Avatar
🏆
Winning The Life

Seyhun Akyürek seyhunak

🏆
Winning The Life
View GitHub Profile
@seyhunak
seyhunak / simple_form.rb
Created Dec 14, 2011
Using simple_form and integrating Twitter Bootstrap
View simple_form.rb
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 Dec 16, 2011 — forked from ryanb/index.js.erb
Infinite scrolling solution covered in revised episode #114: http://railscasts.com/episodes/114-endless-page-revised
View index.js.erb
$('#products').append('<%= j render(@products) %>');
<% if @products.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@products) %>');
<% else %>
$('.pagination').remove();
<% end %>
@seyhunak
seyhunak / list.js
Created Dec 17, 2011
Searching Lists with JQuery
View list.js
$(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 Dec 20, 2011 — forked from vijaydev/gist:1472145
Rails 3.2.0 Changelogs
View gist:1499751

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

View bootstrap_form_builder.rb
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 Jan 17, 2012 — forked from potomak/_flash.html.erb
Rails flash messages using Twitter bootstrap
View _flash.html.erb
<% [: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 Jan 23, 2012 — forked from cbmeeks/bootstrap_form_builder.rb
Twitter Bootstrap Form Builder
View bootstrap_form_builder.rb
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 Jan 23, 2012
Another approach to FormBuilder
View main_form.rb
# 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 Jan 24, 2012 — forked from fxn/Action Mailer
Ruby on Rails v3.2.0 CHANGELOGs
View Action Mailer
## Rails 3.2.0 (January 20, 2012) ##
* Upgrade mail version to 2.4.0 *ML*
* Remove Old ActionMailer API *Josh Kalderimis*
View gist:1694192
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