This repository has been archived by the owner on Dec 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 646
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
60 changed files
with
8,240 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Railscasts Episode #251: MetaWhere & MetaSearch | ||
|
||
http://railscasts.com/episodes/251 | ||
|
||
rails console | ||
|
||
Product.where(:price.lt => 5) | ||
Product.where({:price.lt => 5} | {:name.matches => "%video%"}) | ||
Product.order(:released_at.desc) | ||
MetaWhere.operator_overload! | ||
Product.where(:price < 5) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.bundle | ||
db/*.sqlite3 | ||
log/*.log | ||
tmp/**/* |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
source 'http://rubygems.org' | ||
|
||
gem 'rails', '3.0.3' | ||
|
||
# Bundle edge Rails instead: | ||
# gem 'rails', :git => 'git://github.com/rails/rails.git' | ||
|
||
gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3' | ||
gem 'nifty-generators' | ||
gem 'will_paginate', '3.0.pre2' | ||
gem 'jquery-rails' | ||
|
||
gem "meta_where" | ||
gem "meta_search" | ||
|
||
# Use unicorn as the web server | ||
# gem 'unicorn' | ||
|
||
# Deploy with Capistrano | ||
# gem 'capistrano' | ||
|
||
# To use debugger | ||
# gem 'ruby-debug' | ||
|
||
# Bundle the extra gems: | ||
# gem 'bj' | ||
# gem 'nokogiri', '1.4.1' | ||
# gem 'sqlite3-ruby', :require => 'sqlite3' | ||
# gem 'aws-s3', :require => 'aws/s3' | ||
|
||
# Bundle gems for the local environment. Make sure to | ||
# put test-only gems in this group so their generators | ||
# and rake tasks are available in development mode: | ||
# group :development, :test do | ||
# gem 'webrat' | ||
# end | ||
|
||
gem "hirb", :group => :development |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
abstract (1.0.0) | ||
actionmailer (3.0.3) | ||
actionpack (= 3.0.3) | ||
mail (~> 2.2.9) | ||
actionpack (3.0.3) | ||
activemodel (= 3.0.3) | ||
activesupport (= 3.0.3) | ||
builder (~> 2.1.2) | ||
erubis (~> 2.6.6) | ||
i18n (~> 0.4) | ||
rack (~> 1.2.1) | ||
rack-mount (~> 0.6.13) | ||
rack-test (~> 0.5.6) | ||
tzinfo (~> 0.3.23) | ||
activemodel (3.0.3) | ||
activesupport (= 3.0.3) | ||
builder (~> 2.1.2) | ||
i18n (~> 0.4) | ||
activerecord (3.0.3) | ||
activemodel (= 3.0.3) | ||
activesupport (= 3.0.3) | ||
arel (~> 2.0.2) | ||
tzinfo (~> 0.3.23) | ||
activeresource (3.0.3) | ||
activemodel (= 3.0.3) | ||
activesupport (= 3.0.3) | ||
activesupport (3.0.3) | ||
arel (2.0.6) | ||
builder (2.1.2) | ||
erubis (2.6.6) | ||
abstract (>= 1.0.0) | ||
hirb (0.3.6) | ||
i18n (0.5.0) | ||
jquery-rails (0.2.6) | ||
rails (~> 3.0) | ||
thor (~> 0.14.4) | ||
mail (2.2.12) | ||
activesupport (>= 2.3.6) | ||
i18n (>= 0.4.0) | ||
mime-types (~> 1.16) | ||
treetop (~> 1.4.8) | ||
meta_search (1.0.1) | ||
actionpack (~> 3.0.2) | ||
activerecord (~> 3.0.2) | ||
activesupport (~> 3.0.2) | ||
arel (~> 2.0.2) | ||
meta_where (1.0.1) | ||
activerecord (~> 3.0.2) | ||
activesupport (~> 3.0.2) | ||
arel (~> 2.0.2) | ||
mime-types (1.16) | ||
nifty-generators (0.4.2) | ||
polyglot (0.3.1) | ||
rack (1.2.1) | ||
rack-mount (0.6.13) | ||
rack (>= 1.0.0) | ||
rack-test (0.5.6) | ||
rack (>= 1.0) | ||
rails (3.0.3) | ||
actionmailer (= 3.0.3) | ||
actionpack (= 3.0.3) | ||
activerecord (= 3.0.3) | ||
activeresource (= 3.0.3) | ||
activesupport (= 3.0.3) | ||
bundler (~> 1.0) | ||
railties (= 3.0.3) | ||
railties (3.0.3) | ||
actionpack (= 3.0.3) | ||
activesupport (= 3.0.3) | ||
rake (>= 0.8.7) | ||
thor (~> 0.14.4) | ||
rake (0.8.7) | ||
sqlite3-ruby (1.2.5) | ||
thor (0.14.6) | ||
treetop (1.4.9) | ||
polyglot (>= 0.3.1) | ||
tzinfo (0.3.23) | ||
will_paginate (3.0.pre2) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
hirb | ||
jquery-rails | ||
meta_search | ||
meta_where | ||
nifty-generators | ||
rails (= 3.0.3) | ||
sqlite3-ruby (= 1.2.5) | ||
will_paginate (= 3.0.pre2) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Add your own tasks in files placed in lib/tasks ending in .rake, | ||
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. | ||
|
||
require File.expand_path('../config/application', __FILE__) | ||
require 'rake' | ||
|
||
Store::Application.load_tasks |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class ApplicationController < ActionController::Base | ||
protect_from_forgery | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
class ProductsController < ApplicationController | ||
def index | ||
@search = Product.search(params[:search]) | ||
@products = @search.all | ||
end | ||
|
||
def show | ||
@product = Product.find(params[:id]) | ||
end | ||
|
||
def new | ||
@product = Product.new | ||
end | ||
|
||
def create | ||
@product = Product.new(params[:product]) | ||
if @product.save | ||
redirect_to @product, :notice => "Successfully created product." | ||
else | ||
render :action => "new" | ||
end | ||
end | ||
|
||
def edit | ||
@product = Product.find(params[:id]) | ||
end | ||
|
||
def update | ||
@product = Product.find(params[:id]) | ||
if @product.update_attributes(params[:product]) | ||
redirect_to @product, :notice => "Successfully updated product." | ||
else | ||
render :action => 'edit' | ||
end | ||
end | ||
|
||
def destroy | ||
@product = Product.find(params[:id]) | ||
@product.destroy | ||
redirect_to products_url, :notice => "Successfully destroyed product." | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module ApplicationHelper | ||
def sortable(column, title = nil) | ||
title ||= column.titleize | ||
css_class = column == sort_column ? "current #{sort_direction}" : nil | ||
direction = column == sort_column && sort_direction == "asc" ? "desc" : "asc" | ||
link_to title, params.merge(:sort => column, :direction => direction, :page => nil), {:class => css_class} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module ErrorMessagesHelper | ||
# Render error messages for the given objects. The :message and :header_message options are allowed. | ||
def error_messages_for(*objects) | ||
options = objects.extract_options! | ||
options[:header_message] ||= "Invalid Fields" | ||
options[:message] ||= "Correct the following errors and try again." | ||
messages = objects.compact.map { |o| o.errors.full_messages }.flatten | ||
unless messages.empty? | ||
content_tag(:div, :class => "error_messages") do | ||
list_items = messages.map { |msg| content_tag(:li, msg) } | ||
content_tag(:h2, options[:header_message]) + content_tag(:p, options[:message]) + content_tag(:ul, list_items.join.html_safe) | ||
end | ||
end | ||
end | ||
|
||
module FormBuilderAdditions | ||
def error_messages(options = {}) | ||
@template.error_messages_for(@object, options) | ||
end | ||
end | ||
end | ||
|
||
ActionView::Helpers::FormBuilder.send(:include, ErrorMessagesHelper::FormBuilderAdditions) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# These helper methods can be called in your template to set variables to be used in the layout | ||
# This module should be included in all views globally, | ||
# to do so you may need to add this line to your ApplicationController | ||
# helper :layout | ||
module LayoutHelper | ||
def title(page_title, show_title = true) | ||
content_for(:title) { page_title.to_s } | ||
@show_title = show_title | ||
end | ||
|
||
def show_title? | ||
@show_title | ||
end | ||
|
||
def stylesheet(*args) | ||
content_for(:head) { stylesheet_link_tag(*args) } | ||
end | ||
|
||
def javascript(*args) | ||
content_for(:head) { javascript_include_tag(*args) } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module ProductsHelper | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Product < ActiveRecord::Base | ||
attr_accessible :name, :price, :released_at | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title><%= yield(:title) || "Untitled" %></title> | ||
<%= stylesheet_link_tag "application" %> | ||
<%= javascript_include_tag :defaults %> | ||
<%= csrf_meta_tag %> | ||
<%= yield(:head) %> | ||
</head> | ||
<body> | ||
<div id="container"> | ||
<% flash.each do |name, msg| %> | ||
<%= content_tag :div, msg, :id => "flash_#{name}" %> | ||
<% end %> | ||
<%= content_tag :h1, yield(:title) if show_title? %> | ||
<%= yield %> | ||
</div> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<%= form_for @product do |f| %> | ||
<%= f.error_messages %> | ||
<p> | ||
<%= f.label :name %><br /> | ||
<%= f.text_field :name %> | ||
</p> | ||
<p> | ||
<%= f.label :price %><br /> | ||
<%= f.text_field :price %> | ||
</p> | ||
<p> | ||
<%= f.label :released_at %><br /> | ||
<%= f.datetime_select :released_at %> | ||
</p> | ||
<p><%= f.submit %></p> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<% title "Edit Product" %> | ||
<%= render 'form' %> | ||
|
||
<p> | ||
<%= link_to "Show", @product %> | | ||
<%= link_to "View All", products_path %> | ||
</p> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<% title "Products" %> | ||
<%= form_for @search do |f| %> | ||
<p> | ||
<%= f.label :name_contains %> | ||
<%= f.text_field :name_contains %> | ||
</p> | ||
<p> | ||
<%= f.label :price_gte, "Price ranges from" %> | ||
<%= f.text_field :price_gte, :size => 8 %> | ||
<%= f.label :price_lte, "to" %> | ||
<%= f.text_field :price_lte, :size => 8 %> | ||
</p> | ||
<p class="button"><%= f.submit "Search" %></p> | ||
<% end %> | ||
|
||
<p> | ||
Sort by: | ||
<%= sort_link @search, :name %> | | ||
<%= sort_link @search, :price %> | | ||
<%= sort_link @search, :released_at %> | ||
</p> | ||
|
||
<% for product in @products %> | ||
<div class="product"> | ||
<h2><%= link_to product.name, product %></h2> | ||
<%= number_to_currency(product.price) %> | | ||
Released: <%= product.released_at.strftime("%B %e, %Y") %> | ||
</div> | ||
<% end %> | ||
|
||
<p><%= link_to "New Product", new_product_path %></p> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<% title "New Product" %> | ||
<%= render 'form' %> | ||
|
||
<p><%= link_to "Back to List", products_path %></p> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<% title "Product" %> | ||
|
||
<p> | ||
<strong>Name:</strong> | ||
<%= @product.name %> | ||
</p> | ||
<p> | ||
<strong>Price:</strong> | ||
<%= @product.price %> | ||
</p> | ||
<p> | ||
<strong>Released At:</strong> | ||
<%= @product.released_at %> | ||
</p> | ||
|
||
<p> | ||
<%= link_to "Edit", edit_product_path(@product) %> | | ||
<%= link_to "Destroy", @product, :confirm => 'Are you sure?', :method => :delete %> | | ||
<%= link_to "View All", products_path %> | ||
</p> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# This file is used by Rack-based servers to start the application. | ||
|
||
require ::File.expand_path('../config/environment', __FILE__) | ||
run Store::Application |
Oops, something went wrong.