diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..d591965 --- /dev/null +++ b/Gemfile @@ -0,0 +1,31 @@ +source 'http://rubygems.org' + +gem 'rails', '3.0.0.beta3' + +# Bundle edge Rails instead: +# gem 'rails', :git => 'git://github.com/rails/rails.git' + +gem 'sqlite3-ruby', :require => 'sqlite3' +gem 'nifty-generators' +gem 'authlogic', :git => 'git://github.com/odorcicd/authlogic.git', :branch => 'rails3' +gem 'formtastic', :git => "git://github.com/justinfrench/formtastic.git", :branch => 'rails3' +gem 'cancan' +gem 'activemerchant', :git => 'http://github.com/merbjedi/active_merchant.git', :branch => 'rails3' + +# Use unicorn as the web server +# gem 'unicorn' + +# Deploy with Capistrano +# gem 'capistrano' + +# 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 certain environments: +# gem 'rspec', :group => :test +# group :test do +# gem 'webrat' +# end diff --git a/README b/README new file mode 100644 index 0000000..ded8570 --- /dev/null +++ b/README @@ -0,0 +1,244 @@ +== Welcome to Rails + +Rails is a web-application framework that includes everything needed to create +database-backed web applications according to the Model-View-Control pattern. + +This pattern splits the view (also called the presentation) into "dumb" templates +that are primarily responsible for inserting pre-built data in between HTML tags. +The model contains the "smart" domain objects (such as Account, Product, Person, +Post) that holds all the business logic and knows how to persist themselves to +a database. The controller handles the incoming requests (such as Save New Account, +Update Product, Show Post) by manipulating the model and directing data to the view. + +In Rails, the model is handled by what's called an object-relational mapping +layer entitled Active Record. This layer allows you to present the data from +database rows as objects and embellish these data objects with business logic +methods. You can read more about Active Record in +link:files/vendor/rails/activerecord/README.html. + +The controller and view are handled by the Action Pack, which handles both +layers by its two parts: Action View and Action Controller. These two layers +are bundled in a single package due to their heavy interdependence. This is +unlike the relationship between the Active Record and Action Pack that is much +more separate. Each of these packages can be used independently outside of +Rails. You can read more about Action Pack in +link:files/vendor/rails/actionpack/README.html. + + +== Getting Started + +1. At the command prompt, start a new Rails application using the rails command + and your application name. Ex: rails myapp +2. Change directory into myapp and start the web server: rails server (run with --help for options) +3. Go to http://localhost:3000/ and get "Welcome aboard: You're riding the Rails!" +4. Follow the guidelines to start developing your application + + +== Web Servers + +By default, Rails will try to use Mongrel if it's installed when started with rails server, otherwise +Rails will use WEBrick, the webserver that ships with Ruby. But you can also use Rails +with a variety of other web servers. + +Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is +suitable for development and deployment of Rails applications. If you have Ruby Gems installed, +getting up and running with mongrel is as easy as: gem install mongrel. +More info at: http://mongrel.rubyforge.org + +Say other Ruby web servers like Thin and Ebb or regular web servers like Apache or LiteSpeed or +Lighttpd or IIS. The Ruby web servers are run through Rack and the latter can either be setup to use +FCGI or proxy to a pack of Mongrels/Thin/Ebb servers. + +== Apache .htaccess example for FCGI/CGI + +# General Apache options +AddHandler fastcgi-script .fcgi +AddHandler cgi-script .cgi +Options +FollowSymLinks +ExecCGI + +# If you don't want Rails to look in certain directories, +# use the following rewrite rules so that Apache won't rewrite certain requests +# +# Example: +# RewriteCond %{REQUEST_URI} ^/notrails.* +# RewriteRule .* - [L] + +# Redirect all requests not available on the filesystem to Rails +# By default the cgi dispatcher is used which is very slow +# +# For better performance replace the dispatcher with the fastcgi one +# +# Example: +# RewriteRule ^(.*)$ dispatch.fcgi [QSA,L] +RewriteEngine On + +# If your Rails application is accessed via an Alias directive, +# then you MUST also set the RewriteBase in this htaccess file. +# +# Example: +# Alias /myrailsapp /path/to/myrailsapp/public +# RewriteBase /myrailsapp + +RewriteRule ^$ index.html [QSA] +RewriteRule ^([^.]+)$ $1.html [QSA] +RewriteCond %{REQUEST_FILENAME} !-f +RewriteRule ^(.*)$ dispatch.cgi [QSA,L] + +# In case Rails experiences terminal errors +# Instead of displaying this message you can supply a file here which will be rendered instead +# +# Example: +# ErrorDocument 500 /500.html + +ErrorDocument 500 "
+ <%= link_to "View All", charities_path %> +
diff --git a/app/views/charities/index.html.erb b/app/views/charities/index.html.erb new file mode 100644 index 0000000..c98bf8a --- /dev/null +++ b/app/views/charities/index.html.erb @@ -0,0 +1,17 @@ +<% title "Charities" %> + +Name | +Description | +|
---|---|---|
<%= link_to charity.name, edit_charity_path(charity) %> | +<%= charity.description %> | +<%= link_to "Delete", charity, :confirm => 'Are you sure?', :method => :delete %> | +
<%= link_to "New Charity", new_charity_path %>
diff --git a/app/views/charities/new.html.erb b/app/views/charities/new.html.erb new file mode 100644 index 0000000..ecdb69b --- /dev/null +++ b/app/views/charities/new.html.erb @@ -0,0 +1,5 @@ +<% title "New Charity" %> + +<%= render 'form' %> + +<%= link_to "Back to List", charities_path %>
diff --git a/app/views/charities/show.html.erb b/app/views/charities/show.html.erb new file mode 100644 index 0000000..d1e8e63 --- /dev/null +++ b/app/views/charities/show.html.erb @@ -0,0 +1,16 @@ +<% title "Charity" %> + ++ Name: + <%= @charity.name %> +
++ Description: + <%= @charity.description %> +
+ ++ <%= link_to "Edit", edit_charity_path(@charity) %> | + <%= link_to "Destroy", @charity, :confirm => 'Are you sure?', :method => :delete %> | + <%= link_to "View All", charities_path %> +
diff --git a/app/views/companies/_form.html.erb b/app/views/companies/_form.html.erb new file mode 100644 index 0000000..7159bc0 --- /dev/null +++ b/app/views/companies/_form.html.erb @@ -0,0 +1,11 @@ +<%= semantic_form_for( @company, :html => { :class => 'normal_form' } ) do |f| %> + <%= f.inputs do %> + <%= f.input :name %> + <%= f.input :address %> + <%= f.input :city, :collection => @cities, :group_by => :state, :include_blank => false %> + <%= f.input :zip_code %> + <%= f.input :phone %> + <%= f.input :website %> + <% end %> + <%= image_submit_tag 'submit.png', :class => 'signup' %> +<% end %> diff --git a/app/views/companies/edit.html.erb b/app/views/companies/edit.html.erb new file mode 100644 index 0000000..48bfa54 --- /dev/null +++ b/app/views/companies/edit.html.erb @@ -0,0 +1,7 @@ +<% title "Edit Company" %> + +<%= render 'form' %> + ++ <%= link_to "View All", companies_path %> +
diff --git a/app/views/companies/index.html.erb b/app/views/companies/index.html.erb new file mode 100644 index 0000000..a4f85ab --- /dev/null +++ b/app/views/companies/index.html.erb @@ -0,0 +1,19 @@ +<% title "Companies" %> + +Company | +City | +State | +|
---|---|---|---|
<%= link_to company.name, edit_company_path(company) %> | +<%= company.city.name %> | +<%= company.city.state.abbreviation %> | +<%= link_to "Delete", company, :confirm => 'Are you sure?', :method => :delete %> | +
<%= link_to "New Company", new_company_path %>
diff --git a/app/views/companies/new.html.erb b/app/views/companies/new.html.erb new file mode 100644 index 0000000..6650abd --- /dev/null +++ b/app/views/companies/new.html.erb @@ -0,0 +1,5 @@ +<% title "New Company" %> + +<%= render 'form' %> + +<%= link_to "Back to List", companies_path %>
diff --git a/app/views/companies/show.html.erb b/app/views/companies/show.html.erb new file mode 100644 index 0000000..c0a40d9 --- /dev/null +++ b/app/views/companies/show.html.erb @@ -0,0 +1,22 @@ +<% title "Company" %> + ++ <%= link_to @company.name, edit_company_path(@company) %> +
++ <%= @company.phone %> +
+
+ <%= @company.address %>
+ <%= @company.city.name %>, <%= @company.city.state.abbreviation %> <%= @company.zip_code %>
+
+ <%= link_to @company.website, @company.website, :target => "blank" %> +
++ <%= link_to "Remove", @company, :confirm => 'Are you sure?', :method => :delete %> | + <%= link_to "View All", companies_path %> +
diff --git a/app/views/deals/_form.html.erb b/app/views/deals/_form.html.erb new file mode 100644 index 0000000..2d158aa --- /dev/null +++ b/app/views/deals/_form.html.erb @@ -0,0 +1,18 @@ +<%= semantic_form_for( @deal, :html => { :class => "normal_form"} ) do |f| %> + <%= f.inputs do %> + <%= f.input :name %> + <%= f.input :description %> + <%= f.input :company, :collection => @companies %> + <%= f.input :city, :collection => @cities, :group_by => :state %> + <%= f.input :regular_price %> + <%= f.input :initial_discount %> + <%= f.input :max_discount %> + <%= f.input :max_threshold %> + <%= f.input :deal_date, :as => :string %> + <% if current_user.role == 'admin' %> + <%= f.input :approved %> + <% end %> + <% end %> + + <%= image_submit_tag 'submit.png', :class => 'signup' %> +<% end %> diff --git a/app/views/deals/edit.html.erb b/app/views/deals/edit.html.erb new file mode 100644 index 0000000..4f744d5 --- /dev/null +++ b/app/views/deals/edit.html.erb @@ -0,0 +1,7 @@ +<% title "Edit Deal" %> + +<%= render 'form' %> + ++ <%= link_to "View All", deals_path %> +
diff --git a/app/views/deals/index.html.erb b/app/views/deals/index.html.erb new file mode 100644 index 0000000..f38ab87 --- /dev/null +++ b/app/views/deals/index.html.erb @@ -0,0 +1,25 @@ +<% title "Deals" %> + +Name | +Description | +Regular Price | +Initial Discount | +Max Discount | +Max Threshold | +|
---|---|---|---|---|---|---|
<%= link_to deal.name, edit_deal_path(deal) %> | +<%= deal.description %> | +$<%= deal.regular_price %> | +<%= deal.initial_discount %>% | +<%= deal.max_discount %>% | +<%= deal.max_threshold %> buys | +<%= link_to "Delete", deal, :confirm => 'Are you sure?', :method => :delete %> | +
<%= link_to "New Deal", new_deal_path %>
diff --git a/app/views/deals/new.html.erb b/app/views/deals/new.html.erb new file mode 100644 index 0000000..794e766 --- /dev/null +++ b/app/views/deals/new.html.erb @@ -0,0 +1,5 @@ +<% title "New Deal" %> + +<%= render 'form' %> + +<%= link_to "Back to List", deals_path %>
diff --git a/app/views/deals/show.html.erb b/app/views/deals/show.html.erb new file mode 100644 index 0000000..763108f --- /dev/null +++ b/app/views/deals/show.html.erb @@ -0,0 +1,32 @@ +<% title "Deal" %> + ++ Name: + <%= @deal.name %> +
++ Description: + <%= @deal.description %> +
++ Regular Price: + <%= @deal.regular_price %> +
++ Initial Discount: + <%= @deal.initial_discount %> +
++ Max Discount: + <%= @deal.max_discount %> +
++ Max Threshold: + <%= @deal.max_threshold %> +
+ ++ <%= link_to "Edit", edit_deal_path(@deal) %> | + <%= link_to "Destroy", @deal, :confirm => 'Are you sure?', :method => :delete %> | + <%= link_to "View All", deals_path %> +
diff --git a/app/views/layouts/_adminlinks.html.erb b/app/views/layouts/_adminlinks.html.erb new file mode 100644 index 0000000..a219844 --- /dev/null +++ b/app/views/layouts/_adminlinks.html.erb @@ -0,0 +1,6 @@ +Username | +City | +Registration Date | +||
---|---|---|---|---|
<%= link_to user.username, edit_user_path(user) %> | +<%= user.email %> | +<%= user.city.name %> | +<%= user.created_at.strftime("%b %d, %Y") %> | +<%= link_to "Delete", user, :confirm => 'Are you sure?', :method => :delete %> | +
<%= link_to "New User", register_path %>
diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb new file mode 100644 index 0000000..29d4a57 --- /dev/null +++ b/app/views/users/new.html.erb @@ -0,0 +1,16 @@ +<% title "New User Registration" %> + +<%= semantic_form_for( @user, :html => { :class => "pretty_form" } ) do |f| %> + <%= f.inputs do %> + <%= f.input :username %> + <%= f.input :email %> + <%= f.input :password %> + <%= f.input :password_confirmation %> + <%= f.input :city, :collection => @cities, :group_by => :state, :include_blank => false %> + <% if current_user.try(:role) == 'admin' %> + <%= f.input :role, :collection => User::ROLES %> + <% end %> + <% end %> + + <%= image_submit_tag 'signup.png', :class => 'signup' %> +<% end %> \ No newline at end of file diff --git a/config.ru b/config.ru new file mode 100644 index 0000000..279c6dd --- /dev/null +++ b/config.ru @@ -0,0 +1,4 @@ +# This file is used by Rack-based servers to start the application. + +require ::File.expand_path('../config/environment', __FILE__) +run Sugar::Application diff --git a/config/application.rb b/config/application.rb new file mode 100644 index 0000000..0da7ee2 --- /dev/null +++ b/config/application.rb @@ -0,0 +1,46 @@ +require File.expand_path('../boot', __FILE__) + +require 'rails/all' + +# If you have a Gemfile, require the gems listed there, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(:default, Rails.env) if defined?(Bundler) + +module Sugar + class Application < Rails::Application + # Settings in config/environments/* take precedence over those specified here. + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory are automatically loaded. + + # Add additional load paths for your own custom dirs + # config.load_paths += %W( #{config.root}/extras ) + + # Only load the plugins named here, in the order given (default is alphabetical). + # :all can be used as a placeholder for all plugins not explicitly named + # config.plugins = [ :exception_notification, :ssl_requirement, :all ] + + # Activate observers that should always be running + # config.active_record.observers = :cacher, :garbage_collector, :forum_observer + + # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. + # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. + # config.time_zone = 'Central Time (US & Canada)' + + # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. + # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] + # config.i18n.default_locale = :de + + # Configure generators values. Many other options are available, be sure to check the documentation. + # config.generators do |g| + # g.orm :active_record + # g.template_engine :erb + # g.test_framework :test_unit, :fixture => true + # end + + # Configure the default encoding used in templates for Ruby 1.9. + config.encoding = "utf-8" + + # Configure sensitive parameters which will be filtered from the log file. + config.filter_parameters += [:password, :password_confirmation] + end +end diff --git a/config/boot.rb b/config/boot.rb new file mode 100644 index 0000000..712b098 --- /dev/null +++ b/config/boot.rb @@ -0,0 +1,6 @@ +require 'rubygems' +# Set up gems listed in the Gemfile. +if File.exist?(File.expand_path('../../Gemfile', __FILE__)) + require 'bundler' + Bundler.setup +end diff --git a/config/environment.rb b/config/environment.rb new file mode 100644 index 0000000..e140b49 --- /dev/null +++ b/config/environment.rb @@ -0,0 +1,5 @@ +# Load the rails application +require File.expand_path('../application', __FILE__) + +# Initialize the rails application +Sugar::Application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb new file mode 100644 index 0000000..bc65c3f --- /dev/null +++ b/config/environments/development.rb @@ -0,0 +1,33 @@ +Sugar::Application.configure do + # Settings specified here will take precedence over those in config/environment.rb + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the webserver when you make code changes. + config.cache_classes = false + + # Log error messages when you accidentally call methods on nil. + config.whiny_nils = true + + # Show full error reports and disable caching + config.consider_all_requests_local = true + config.action_view.debug_rjs = true + config.action_controller.perform_caching = false + + # Don't care if the mailer can't send + config.action_mailer.raise_delivery_errors = false + + # ActiveMerchant setup + # config.after_initialize do + # ActiveMerchant::Billing::Base.mode = :test + # end + # + # config.to_prepare do + # OrderTransaction.gateway = + # ActiveMerchant::Billing::AuthorizeNetGateway.new( + # :login => '8Y6gAv8p', + # :password => '326EsxLh5252W7ku', + # :test => true + # ) + # end +end diff --git a/config/environments/production.rb b/config/environments/production.rb new file mode 100644 index 0000000..7435bdd --- /dev/null +++ b/config/environments/production.rb @@ -0,0 +1,42 @@ +Sugar::Application.configure do + # Settings specified here will take precedence over those in config/environment.rb + + # The production environment is meant for finished, "live" apps. + # Code is not reloaded between requests + config.cache_classes = true + + # Full error reports are disabled and caching is turned on + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Specifies the header that your server uses for sending files + config.action_dispatch.x_sendfile_header = "X-Sendfile" + + # For nginx: + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' + + # If you have no front-end server that supports something like X-Sendfile, + # just comment this out and Rails will serve the files + + # See everything in the log (default is :info) + # config.log_level = :debug + + # Use a different logger for distributed setups + # config.logger = SyslogLogger.new + + # Use a different cache store in production + # config.cache_store = :mem_cache_store + + # Disable Rails's static asset server + # In production, Apache or nginx will already do this + config.serve_static_assets = false + + # Enable serving of images, stylesheets, and javascripts from an asset server + # config.action_controller.asset_host = "http://assets.example.com" + + # Disable delivery errors, bad email addresses will be ignored + # config.action_mailer.raise_delivery_errors = false + + # Enable threaded mode + # config.threadsafe! +end diff --git a/config/environments/test.rb b/config/environments/test.rb new file mode 100644 index 0000000..3ba3ef6 --- /dev/null +++ b/config/environments/test.rb @@ -0,0 +1,32 @@ +Sugar::Application.configure do + # Settings specified here will take precedence over those in config/environment.rb + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Log error messages when you accidentally call methods on nil. + config.whiny_nils = true + + # Show full error reports and disable caching + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment + config.action_controller.allow_forgery_protection = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Use SQL instead of Active Record's schema dumper when creating the test database. + # This is necessary if your schema can't be completely dumped by the schema dumper, + # like if you have constraints or database-specific column types + # config.active_record.schema_format = :sql +end diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000..59385cd --- /dev/null +++ b/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/config/initializers/formtastic.rb b/config/initializers/formtastic.rb new file mode 100644 index 0000000..9fd7eea --- /dev/null +++ b/config/initializers/formtastic.rb @@ -0,0 +1,73 @@ +# Set the default text field size when input is a string. Default is 50. +# Formtastic::SemanticFormBuilder.default_text_field_size = 50 + +# Set the default text area height when input is a text. Default is 20. +Formtastic::SemanticFormBuilder.default_text_area_height = 5 + +# Should all fields be considered "required" by default? +# Defaults to true, see ValidationReflection notes below. +# Formtastic::SemanticFormBuilder.all_fields_required_by_default = true + +# Should select fields have a blank option/prompt by default? +# Defaults to true. +Formtastic::SemanticFormBuilder.include_blank_for_select_by_default = false + +# Set the string that will be appended to the labels/fieldsets which are required +# It accepts string or procs and the default is a localized version of +# '*'. In other words, if you configure formtastic.required +# in your locale, it will replace the abbr title properly. But if you don't want to use +# abbr tag, you can simply give a string as below +# Formtastic::SemanticFormBuilder.required_string = "(required)" + +# Set the string that will be appended to the labels/fieldsets which are optional +# Defaults to an empty string ("") and also accepts procs (see required_string above) +# Formtastic::SemanticFormBuilder.optional_string = "(optional)" + +# Set the way inline errors will be displayed. +# Defaults to :sentence, valid options are :sentence, :list and :none +Formtastic::SemanticFormBuilder.inline_errors = :sentence + +# Set the method to call on label text to transform or format it for human-friendly +# reading when formtastic is user without object. Defaults to :humanize. +# Formtastic::SemanticFormBuilder.label_str_method = :humanize + +# Set the array of methods to try calling on parent objects in :select and :radio inputs +# for the text inside each @