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
# In Layouts | |
<head> | |
<title><%= content_for?(:title) ? yield(:title) : "Untitled" %></title> | |
<%= javascript_include_tag :defaults %> | |
<%= stylesheet_link_tag "style", "theme" %> | |
<%= csrf_meta_tag %> | |
<%= yield(:head) %> | |
<%= javascript_include_tag "admin" %> | |
<% if @cartridge&&@printers %> | |
<script type="text/javascript"> |
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
<input type="text" class="add_to_cart_quantity"> | |
<input type="submit" class="add_to_cart_button"> | |
<input type="text" class="add_to_cart_quantity"> | |
<input type="submit" class="add_to_cart_button"> |
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
# AJAX request: This adds line items to cart. | |
def add_line_item_to_cart | |
#Get current_cart object | |
current_cart | |
quantity = params[:quantity].to_i | |
id = params[:id].to_i | |
line_item = LineItem.find(:first, :conditions => {:cartridge_id => id, :cart_id => current_cart.id}) | |
#If there is line item wich maches conditions then just update quantity | |
#Returns quantity with total of items in cart | |
if line_item != nil |
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
#In controller | |
@clients_ip = request.remote_ip | |
@comments = @user.comments.ordered | |
#In views | |
<% for comment in @comments %> | |
<div class="comment <%= gender_check(comment.gender) %>"> | |
<div class="created_at"><%= comment.created_at.strftime("%H:%M") %></div> | |
<div class="comment_rating"> | |
<span class="rating"><%= comment.rating %></span> | |
<span class="thumbs" value="<%= comment.id %>"> |
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 Tracker < ActiveRecord::Base | |
attr_accessible :survey_id, :respondent_id, :progress, :completed | |
belongs_to :survey | |
after_save :set_completed? | |
#set tracker.completed to true if all questions are answered | |
def set_completed? | |
if progress >= survey.questions.count |
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
[25] pry(main)> t.route_ids = [1,1,1] | |
=> [1, 1, 1] | |
[26] pry(main)> t.route_ids | |
=> [1] |
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
[25] pry(main)> t.route_ids = [1,1,1] | |
=> [1, 1, 1] | |
[26] pry(main)> t.route_ids | |
=> [1] |
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
# MongoDB vs MySQL test for creating and destroying 10000 recordst. | |
# Was using faker gem to generate random text for body and content | |
# Code for Benchmark | |
def self.do_bm | |
Benchmark.bm do |x| | |
x.report do | |
10000.times do | |
self.create(:title => Faker::Lorem.sentence, :body => Faker::Lorem.paragraph(10)) |
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 new | |
if current_user && current_user.has_products? | |
redirect_to :action => :edit | |
elsif current_user && current_user.has_no_products? | |
current_user.create_product! | |
redirect_to :action => :edit | |
else | |
redirect_to root_url | |
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
require 'mime/types' | |
# | |
# Built with massive inspiration (ok, more like following their lead) from the following: | |
# - https://github.com/JackDanger/file-uploader/commit/03ed9ba68d46805e22a0014ac0eee9ecbd5acd8d | |
# - https://github.com/newbamboo/example-html5-upload/blob/master/lib/rack/raw_upload.rb | |
# | |
class RawFileUpload | |
def initialize(app) | |
@app = app |
OlderNewer