Started inital migration to rails 3.2

This commit is contained in:
2013-01-19 01:14:55 -05:00
parent 64aff15deb
commit a9a4cd892f
98 changed files with 968 additions and 363 deletions

28
.gitignore vendored
View File

@@ -1,13 +1,15 @@
.bundle # See http://help.github.com/ignore-files/ for more about ignoring files.
db/*.sqlite3 #
log/*.log # If you find yourself ignoring temporary files generated by your text editor
tmp/ # or operating system, you probably want to add a global ignore instead:
.DS_Store # git config --global core.excludesfile ~/.gitignore_global
._*
.redcar # Ignore bundler config
.rvmrc* /.bundle
config/database.yml
*.swp # Ignore the default SQLite database.
config/dev /db/*.sqlite3
public/assets
public/uploads # Ignore all logfiles and tempfiles.
/log/*.log
/tmp

41
Gemfile
View File

@@ -1,7 +1,22 @@
source 'http://rubygems.org' source 'https://rubygems.org'
gem 'rails', '3.0.9' gem 'rails', '3.2.11'
gem 'sqlite3'
gem 'mysql2'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'execjs'
gem 'forum_monster', '~> 1.0.3' gem 'forum_monster', '~> 1.0.3'
gem 'devise' gem 'devise'
@@ -9,11 +24,21 @@ gem 'cancan'
gem 'gravtastic', :git => 'https://github.com/chrislloyd/gravtastic.git' gem 'gravtastic', :git => 'https://github.com/chrislloyd/gravtastic.git'
gem 'bb-ruby' gem 'bb-ruby'
group :development do
gem 'hirb'
gem 'heroku'
end
group :production do group :production do
gem 'unicorn' gem 'unicorn'
end end
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'

View File

@@ -1,105 +1,124 @@
GIT GIT
remote: https://github.com/chrislloyd/gravtastic.git remote: https://github.com/chrislloyd/gravtastic.git
revision: 2b2252c0aee98854d94f040d88a9f70c1da3097d revision: bfe15aa77cf9fa4c05cc20f7059955ac90a4e205
specs: specs:
gravtastic (3.2.6) gravtastic (3.2.6)
GEM GEM
remote: http://rubygems.org/ remote: https://rubygems.org/
specs: specs:
abstract (1.0.0) actionmailer (3.2.11)
actionmailer (3.0.9) actionpack (= 3.2.11)
actionpack (= 3.0.9) mail (~> 2.4.4)
mail (~> 2.2.19) actionpack (3.2.11)
actionpack (3.0.9) activemodel (= 3.2.11)
activemodel (= 3.0.9) activesupport (= 3.2.11)
activesupport (= 3.0.9) builder (~> 3.0.0)
builder (~> 2.1.2) erubis (~> 2.7.0)
erubis (~> 2.6.6) journey (~> 1.0.4)
i18n (~> 0.5.0) rack (~> 1.4.0)
rack (~> 1.2.1) rack-cache (~> 1.2)
rack-mount (~> 0.6.14) rack-test (~> 0.6.1)
rack-test (~> 0.5.7) sprockets (~> 2.2.1)
tzinfo (~> 0.3.23) activemodel (3.2.11)
activemodel (3.0.9) activesupport (= 3.2.11)
activesupport (= 3.0.9) builder (~> 3.0.0)
builder (~> 2.1.2) activerecord (3.2.11)
i18n (~> 0.5.0) activemodel (= 3.2.11)
activerecord (3.0.9) activesupport (= 3.2.11)
activemodel (= 3.0.9) arel (~> 3.0.2)
activesupport (= 3.0.9) tzinfo (~> 0.3.29)
arel (~> 2.0.10) activeresource (3.2.11)
tzinfo (~> 0.3.23) activemodel (= 3.2.11)
activeresource (3.0.9) activesupport (= 3.2.11)
activemodel (= 3.0.9) activesupport (3.2.11)
activesupport (= 3.0.9) i18n (~> 0.6)
activesupport (3.0.9) multi_json (~> 1.0)
addressable (2.2.6) arel (3.0.2)
arel (2.0.10) bb-ruby (0.9.8)
bb-ruby (0.9.5) bcrypt-ruby (3.0.1)
bcrypt-ruby (2.1.4) builder (3.0.4)
builder (2.1.2) cancan (1.6.8)
cancan (1.6.5) coffee-rails (3.2.2)
devise (1.4.2) coffee-script (>= 2.2.0)
bcrypt-ruby (~> 2.1.2) railties (~> 3.2.0)
orm_adapter (~> 0.0.3) coffee-script (2.2.0)
warden (~> 1.0.3) coffee-script-source
erubis (2.6.6) execjs
abstract (>= 1.0.0) coffee-script-source (1.4.0)
forum_monster (1.0.3) devise (2.2.2)
heroku (2.17.0) bcrypt-ruby (~> 3.0)
launchy (>= 0.3.2) orm_adapter (~> 0.1)
rest-client (~> 1.6.1) railties (~> 3.1)
rubyzip warden (~> 1.2.1)
term-ansicolor (~> 1.0.5) erubis (2.7.0)
hirb (0.5.0) execjs (1.4.0)
i18n (0.5.0) multi_json (~> 1.0)
kgio (2.4.1) forum_monster (1.0.4)
launchy (2.0.5) hike (1.2.1)
addressable (~> 2.2.6) i18n (0.6.1)
mail (2.2.19) journey (1.0.4)
activesupport (>= 2.3.6) json (1.7.6)
kgio (2.7.4)
mail (2.4.4)
i18n (>= 0.4.0) i18n (>= 0.4.0)
mime-types (~> 1.16) mime-types (~> 1.16)
treetop (~> 1.4.8) treetop (~> 1.4.8)
mime-types (1.16) mime-types (1.19)
orm_adapter (0.0.5) multi_json (1.5.0)
polyglot (0.3.2) mysql2 (0.3.11)
rack (1.2.3) orm_adapter (0.4.0)
rack-mount (0.6.14) polyglot (0.3.3)
rack (>= 1.0.0) rack (1.4.4)
rack-test (0.5.7) rack-cache (1.2)
rack (>= 0.4)
rack-ssl (1.3.2)
rack
rack-test (0.6.2)
rack (>= 1.0) rack (>= 1.0)
rails (3.0.9) rails (3.2.11)
actionmailer (= 3.0.9) actionmailer (= 3.2.11)
actionpack (= 3.0.9) actionpack (= 3.2.11)
activerecord (= 3.0.9) activerecord (= 3.2.11)
activeresource (= 3.0.9) activeresource (= 3.2.11)
activesupport (= 3.0.9) activesupport (= 3.2.11)
bundler (~> 1.0) bundler (~> 1.0)
railties (= 3.0.9) railties (= 3.2.11)
railties (3.0.9) railties (3.2.11)
actionpack (= 3.0.9) actionpack (= 3.2.11)
activesupport (= 3.0.9) activesupport (= 3.2.11)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7) rake (>= 0.8.7)
rdoc (~> 3.4) rdoc (~> 3.4)
thor (~> 0.14.4) thor (>= 0.14.6, < 2.0)
rake (0.9.2) raindrops (0.10.0)
rdoc (3.9.1) rake (10.0.3)
rest-client (1.6.7) rdoc (3.12)
mime-types (>= 1.16) json (~> 1.4)
rubyzip (0.9.5) sass (3.2.5)
sqlite3 (1.3.4) sass-rails (3.2.6)
term-ansicolor (1.0.7) railties (~> 3.2.0)
thor (0.14.6) sass (>= 3.1.10)
treetop (1.4.10) tilt (~> 1.3)
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
thor (0.16.0)
tilt (1.3.3)
treetop (1.4.12)
polyglot polyglot
polyglot (>= 0.3.1) polyglot (>= 0.3.1)
tzinfo (0.3.29) tzinfo (0.3.35)
unicorn (3.6.2) uglifier (1.3.0)
kgio (~> 2.3) execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
unicorn (4.5.0)
kgio (~> 2.6)
rack rack
warden (1.0.5) raindrops (~> 0.7)
warden (1.2.1)
rack (>= 1.0) rack (>= 1.0)
PLATFORMS PLATFORMS
@@ -108,11 +127,13 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
bb-ruby bb-ruby
cancan cancan
coffee-rails (~> 3.2.1)
devise devise
execjs
forum_monster (~> 1.0.3) forum_monster (~> 1.0.3)
gravtastic! gravtastic!
heroku mysql2
hirb rails (= 3.2.11)
rails (= 3.0.9) sass-rails (~> 3.2.3)
sqlite3 uglifier (>= 1.0.3)
unicorn unicorn

View File

@@ -1,42 +1,261 @@
== Forum Monster Demo == Welcome to Rails
Demo for Forum Monster Forum Gem Rails is a web-application framework that includes everything needed to create
https://github.com/gitt/forum_monster database-backed web applications according to the Model-View-Control pattern.
Live demo available here This pattern splits the view (also called the presentation) into "dumb"
http://forum-monster.heroku.com 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.
This demo is setup for you to play around with, and get an idea on how you can use Forum Monster. This demo includes a lot of extra functionality that doesn't come with Forum Monster by default. 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.
Gems Used in the demo are: 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.
bb-ruby ( bb-code ): https://github.com/cpjolicoeur/bb-ruby
devise ( user authentication ): https://github.com/plataformatec/devise == Getting Started
cancan ( user authorization ): https://github.com/ryanb/cancan 1. At the command prompt, create a new Rails application:
<tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
gravtastic ( user avatars ): https://github.com/chrislloyd/gravtastic 2. Change directory to <tt>myapp</tt> and start the web server:
<tt>cd myapp; rails server</tt> (run with --help for options)
== Installation 3. Go to http://localhost:3000/ and you'll see:
"Welcome aboard: You're riding Ruby on Rails!"
Just download, bundle, and run. 4. Follow the guidelines to start developing your application. You can find
the following resources handy:
git clone git@github.com:gitt/forum_monster_demo.git * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
cd forum_monster_demo
bundle install
rake db:create == Debugging Rails
rake db:migrate
rake db:seed
rails s Sometimes your application goes wrong. Fortunately there are a lot of tools that
will help you debug it and get it back on the rails.
2 Logins, 2 categories, and 5 forums are already setup for you to play with. You can create more as well First area to check is the application log files. Have "tail -f" commands
running on the server.log and development.log. Rails will automatically display
debugging and runtime information to these files. Debugging info will also be
shown in the browser on requests from 127.0.0.1.
The admin login is admin/forum_admin You can also log your own messages directly into the log file from your code
using the Ruby logger class from inside your controllers. Example:
The user login is user/forum_user class WeblogController < ActionController::Base
def destroy
@weblog = Weblog.find(params[:id])
@weblog.destroy
logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
end
end
In addition to the 2 above users, you can use the registration process as normal. The result will be a message in your log file along the lines of:
Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
More information on how to use the logger is at http://www.ruby-doc.org/core/
Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
several books available online as well:
* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
These two books will bring you up to speed on the Ruby language and also on
programming in general.
== Debugger
Debugger support is available through the debugger command when you start your
Mongrel or WEBrick server with --debugger. This means that you can break out of
execution at any point in the code, investigate and change the model, and then,
resume execution! You need to install ruby-debug to run the server in debugging
mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
class WeblogController < ActionController::Base
def index
@posts = Post.all
debugger
end
end
So the controller will accept the action, run the first line, then present you
with a IRB prompt in the server window. Here you can do things like:
>> @posts.inspect
=> "[#<Post:0x14a6be8
@attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
#<Post:0x14a6620
@attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
>> @posts.first.title = "hello from a debugger"
=> "hello from a debugger"
...and even better, you can examine how your runtime objects actually work:
>> f = @posts.first
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
>> f.
Display all 152 possibilities? (y or n)
Finally, when you're ready to resume execution, you can enter "cont".
== Console
The console is a Ruby shell, which allows you to interact with your
application's domain model. Here you'll have all parts of the application
configured, just like it is when the application is running. You can inspect
domain models, change values, and save to the database. Starting the script
without arguments will launch it in the development environment.
To start the console, run <tt>rails console</tt> from the application
directory.
Options:
* Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
made to the database.
* Passing an environment name as an argument will load the corresponding
environment. Example: <tt>rails console production</tt>.
To reload your controllers and models after launching the console run
<tt>reload!</tt>
More information about irb can be found at:
link:http://www.rubycentral.org/pickaxe/irb.html
== dbconsole
You can go to the command line of your database directly through <tt>rails
dbconsole</tt>. You would be connected to the database with the credentials
defined in database.yml. Starting the script without arguments will connect you
to the development database. Passing an argument will connect you to a different
database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
PostgreSQL and SQLite 3.
== Description of Contents
The default directory structure of a generated Ruby on Rails application:
|-- app
| |-- assets
| |-- images
| |-- javascripts
| `-- stylesheets
| |-- controllers
| |-- helpers
| |-- mailers
| |-- models
| `-- views
| `-- layouts
|-- config
| |-- environments
| |-- initializers
| `-- locales
|-- db
|-- doc
|-- lib
| `-- tasks
|-- log
|-- public
|-- script
|-- test
| |-- fixtures
| |-- functional
| |-- integration
| |-- performance
| `-- unit
|-- tmp
| |-- cache
| |-- pids
| |-- sessions
| `-- sockets
`-- vendor
|-- assets
`-- stylesheets
`-- plugins
app
Holds all the code that's specific to this particular application.
app/assets
Contains subdirectories for images, stylesheets, and JavaScript files.
app/controllers
Holds controllers that should be named like weblogs_controller.rb for
automated URL mapping. All controllers should descend from
ApplicationController which itself descends from ActionController::Base.
app/models
Holds models that should be named like post.rb. Models descend from
ActiveRecord::Base by default.
app/views
Holds the template files for the view that should be named like
weblogs/index.html.erb for the WeblogsController#index action. All views use
eRuby syntax by default.
app/views/layouts
Holds the template files for layouts to be used with views. This models the
common header/footer method of wrapping views. In your views, define a layout
using the <tt>layout :default</tt> and create a file named default.html.erb.
Inside default.html.erb, call <% yield %> to render the view using this
layout.
app/helpers
Holds view helpers that should be named like weblogs_helper.rb. These are
generated for you automatically when using generators for controllers.
Helpers can be used to wrap functionality for your views into methods.
config
Configuration files for the Rails environment, the routing map, the database,
and other dependencies.
db
Contains the database schema in schema.rb. db/migrate contains all the
sequence of Migrations for your schema.
doc
This directory is where your application documentation will be stored when
generated using <tt>rake doc:app</tt>
lib
Application specific libraries. Basically, any kind of custom code that
doesn't belong under controllers, models, or helpers. This directory is in
the load path.
public
The directory available for the web server. Also contains the dispatchers and the
default HTML files. This should be set as the DOCUMENT_ROOT of your web
server.
script
Helper scripts for automation and generation.
test
Unit and functional tests along with fixtures. When using the rails generate
command, template test files will be generated for you and placed in this
directory.
vendor
External libraries that the application depends on. Also includes the plugins
subdirectory. If the app has frozen rails, those gems also go here, under
vendor/rails/. This directory is in the load path.

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env rake
# Add your own tasks in files placed in lib/tasks ending in .rake, # 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. # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__) require File.expand_path('../config/application', __FILE__)
require 'rake'
Community::Application.load_tasks Community::Application.load_tasks

View File

Before

Width:  |  Height:  |  Size: 122 B

After

Width:  |  Height:  |  Size: 122 B

View File

Before

Width:  |  Height:  |  Size: 550 B

After

Width:  |  Height:  |  Size: 550 B

View File

Before

Width:  |  Height:  |  Size: 758 B

After

Width:  |  Height:  |  Size: 758 B

View File

Before

Width:  |  Height:  |  Size: 628 B

After

Width:  |  Height:  |  Size: 628 B

View File

Before

Width:  |  Height:  |  Size: 852 B

After

Width:  |  Height:  |  Size: 852 B

View File

Before

Width:  |  Height:  |  Size: 640 B

After

Width:  |  Height:  |  Size: 640 B

View File

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

0
public/images/ruby.png → app/assets/images/ruby.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

Before

Width:  |  Height:  |  Size: 115 B

After

Width:  |  Height:  |  Size: 115 B

View File

@@ -1,2 +1,3 @@
// Place your application-specific JavaScript functions and classes here // Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults // This file is automatically included by javascript_include_tag :defaults
//= require_tree .

View File

View File

0
public/javascripts/effects.js → app/assets/javascripts/effects.js vendored Normal file → Executable file
View File

View File

View File

View File

View File

@@ -1,3 +1,8 @@
/*
*= require_self
*= require_tree .
*/
body { body {
font-family: Verdana, Helvetica, Arial; font-family: Verdana, Helvetica, Arial;
font-size: 12px; font-size: 12px;

0
app/controllers/application_controller.rb Normal file → Executable file
View File

0
app/controllers/categories_controller.rb Normal file → Executable file
View File

0
app/controllers/forums_controller.rb Normal file → Executable file
View File

0
app/controllers/posts_controller.rb Normal file → Executable file
View File

0
app/controllers/topics_controller.rb Normal file → Executable file
View File

View File

@@ -0,0 +1,95 @@
class UsersController < ApplicationController
before_filter :authenticate_user!
before_filter :is_admin?
# GET /users
# GET /users.json
def index
@users = User.all
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @users }
end
end
# GET /users/1
# GET /users/1.json
def show
@user = User.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render :json => @user }
end
end
# GET /users/new
# GET /users/new.json
def new
@user = User.new
respond_to do |format|
format.html # new.html.erb
format.json { render :json => @user }
end
end
# GET /users/1/edit
def edit
@user = User.find(params[:id])
end
# POST /users
# POST /users.json
def create
@user = User.new(params[:user])
respond_to do |format|
if @user.save
format.html { redirect_to @user, :notice => 'User was successfully created.' }
format.json { render :json => @user, :status => :created, :location => @user }
else
format.html { render :action => "new" }
format.json { render :json => @user.errors, :status => :unprocessable_entity }
end
end
end
# PUT /users/1
# PUT /users/1.json
def update
@user = User.find(params[:id])
respond_to do |format|
if @user.update_attributes(params[:user])
format.html { redirect_to @user, :notice => 'User was successfully updated.' }
format.json { head :ok }
else
format.html { render :action => "edit" }
format.json { render :json => @user.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /users/1
# DELETE /users/1.json
def destroy
@user = User.find(params[:id])
@user.destroy
respond_to do |format|
format.html { redirect_to users_url }
format.json { head :ok }
end
end
def is_admin?
unless (current_user && current_user.admin?)
flash[:error] = 'You are not an Admin'
redirect_to root_path
end
end
end

0
app/helpers/application_helper.rb Normal file → Executable file
View File

0
app/helpers/error_messages_helper.rb Normal file → Executable file
View File

0
app/helpers/layout_helper.rb Normal file → Executable file
View File

View File

@@ -28,7 +28,7 @@ class Topic < ActiveRecord::Base
private private
def create_initial_post def create_initial_post
returning self.posts.build(:body => self.body) do |post| self.posts.build(:body => self.body).tap do |post|
post.forum = self.forum post.forum = self.forum
post.user = self.user post.user = self.user
post.save post.save

0
app/views/categories/_form.html.erb Normal file → Executable file
View File

0
app/views/categories/edit.html.erb Normal file → Executable file
View File

0
app/views/categories/index.html.erb Normal file → Executable file
View File

0
app/views/categories/new.html.erb Normal file → Executable file
View File

0
app/views/devise/confirmations/new.html.erb Normal file → Executable file
View File

View File

View File

0
app/views/devise/mailer/unlock_instructions.html.erb Normal file → Executable file
View File

0
app/views/devise/passwords/edit.html.erb Normal file → Executable file
View File

0
app/views/devise/passwords/new.html.erb Normal file → Executable file
View File

5
app/views/devise/registrations/edit.html.erb Normal file → Executable file
View File

@@ -6,6 +6,11 @@
<p><%= f.label :email %><br /> <p><%= f.label :email %><br />
<%= f.email_field :email %></p> <%= f.email_field :email %></p>
<% if current_user.admin? %>
<p><%= f.label :is_admin %><br />
<%= f.check_box :is_admin, {checked: resource.admin?} %></p>
<% end %>
<p><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br /> <p><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password %></p> <%= f.password_field :password %></p>

5
app/views/devise/registrations/new.html.erb Normal file → Executable file
View File

@@ -1,8 +1,7 @@
<div class="module" style="padding:15px 25px 0px 25px;"> <div class="module" style="padding:15px 25px 0px 25px;">
<div style="float:left; width:50%; height:330px; padding-right:10px;"> <div style="float:left; width:50%; height:330px; padding-right:10px;">
<h1>Welcome to Forum Monster</h1> <h1>Welcome to Horses</h1>
<p>Forum Monster is a simple forum generator written in rails 3. The goal of Forum Monster, is to provide a simple, and easy to setup forum application without having to dictate how your site it setup.</p> <%= devise_error_messages! %>
<p style="font-size:1.2em;"><strong>The email field is required, but none of the data is saved for more than a day. Feel free to put in a fake address.</strong></p>
</div> </div>
<div style="float:right; width:45%; padding-left:30px; border-left:1px solid #e2e2e2;"> <div style="float:right; width:45%; padding-left:30px; border-left:1px solid #e2e2e2;">
<%= form_for("user", :as => resource_name, :url => registration_path("user")) do |f| %> <%= form_for("user", :as => resource_name, :url => registration_path("user")) do |f| %>

8
app/views/devise/sessions/new.html.erb Normal file → Executable file
View File

@@ -19,13 +19,7 @@
<div class="module" style="padding:15px 25px 0px 25px;"> <div class="module" style="padding:15px 25px 0px 25px;">
<div style="float:left; width:50%; height:210px; padding-right:10px;"> <div style="float:left; width:50%; height:210px; padding-right:10px;">
<h1>Welcome to Forum Monster</h1> <h1>Welcome to Horses</h1>
<p>
Forum Monster is a simple forum generator written in rails 3. The goal of Forum Monster, is to provide a simple, and easy to setup forum application without having to dictate how your site it setup.
<p>You can login with the following information:</p>
<p><strong>Admin Demo:</strong> admin/forum_admin</p>
<p><strong>User Demo:</strong> user/forum_user</p>
</p>
</div> </div>
<div style="float:right; width:45%; height:195px; padding-left:30px; border-left:1px solid #e2e2e2;"> <div style="float:right; width:45%; height:195px; padding-left:30px; border-left:1px solid #e2e2e2;">
<%= form_for("user", :url => user_session_path) do |f| %> <%= form_for("user", :url => user_session_path) do |f| %>

0
app/views/devise/shared/_links.erb Normal file → Executable file
View File

0
app/views/devise/unlocks/new.html.erb Normal file → Executable file
View File

0
app/views/forums/_form.html.erb Normal file → Executable file
View File

0
app/views/forums/edit.html.erb Normal file → Executable file
View File

0
app/views/forums/index.html.erb Normal file → Executable file
View File

0
app/views/forums/new.html.erb Normal file → Executable file
View File

0
app/views/forums/show.html.erb Normal file → Executable file
View File

17
app/views/layouts/application.html.erb Normal file → Executable file
View File

@@ -1,30 +1,27 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title><%= content_for?(:title) ? yield(:title) : "Untitled" %></title> <title><%= content_for?(:title) ? yield(:title) : "Horses" %></title>
<%= stylesheet_link_tag "application", "forum-monster" %> <%= stylesheet_link_tag "application", "forum-monster" %>
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %> <%= csrf_meta_tag %>
<%= yield(:head) %> <%= yield(:head) %>
</head> </head>
<body> <body>
<a href="https://github.com/gitt/forum_monster"><img style="position: absolute; top: 0; left: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_left_red_aa0000.png" alt="Fork me on GitHub"></a>
<div class="container">
<%= content_tag :div, "This is just a demo, the database is reset every 24 hours.", :class => "demo_notice" %>
</div>
<div id="header"> <div id="header">
<div id="logo"> <div id="logo">
<%= image_tag "rails.png" %> <%= image_tag "rails.png" %>
<h1>Forum Monster</h1> <h1>Horses</h1>
A Ruby on Rails Forum Gem A forum about Horses
<div class="clear"></div> <div class="clear"></div>
</div> </div>
<div id="menu_wrapper"> <div id="menu_wrapper">
<ul> <ul>
<li><%= link_to "Forum Index", root_path %></li> <li><%= link_to "Forum Index", root_path %></li>
<% if user_signed_in? %> <% if user_signed_in? %>
<li><%= link_to "User Control Panel", edit_user_registration_path %></li>
<% if current_user.admin? %>
<li><%= link_to "User Administration", users_path %></li>
<% end %>
<li><%= link_to "Logout", destroy_user_session_path, :method => :delete %></li> <li><%= link_to "Logout", destroy_user_session_path, :method => :delete %></li>
<% else %> <% else %>
<li><%= link_to "Login", new_user_session_path %></li> <li><%= link_to "Login", new_user_session_path %></li>

0
app/views/posts/_form.html.erb Normal file → Executable file
View File

0
app/views/posts/edit.html.erb Normal file → Executable file
View File

0
app/views/posts/new.html.erb Normal file → Executable file
View File

0
app/views/topics/_form.html.erb Normal file → Executable file
View File

0
app/views/topics/edit.html.erb Normal file → Executable file
View File

0
app/views/topics/new.html.erb Normal file → Executable file
View File

2
app/views/topics/show.html.erb Normal file → Executable file
View File

@@ -19,7 +19,7 @@
<span class="info smaller"> <span class="info smaller">
<p><strong><%= "Administrator" if post.user.admin? %></strong></p> <p><strong><%= "Administrator" if post.user.admin? %></strong></p>
Posts <%= post.user.posts.size %><br /> Posts <%= post.user.posts.size %><br />
Registered <%=l post.user.created_at, :format => :joined %><br /> Registered <%=l post.user.created_at %><br />
</span> </span>
</td> </td>
<td class="post_header"> <td class="post_header">

34
app/views/users/_form.html.erb Executable file
View File

@@ -0,0 +1,34 @@
<%= form_for(@user) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<p><%= f.label :username %><br />
<%= f.text_field :username %></p>
<p><%= f.label :is_admin %>
<%= f.check_box :is_admin, {checked: @user.admin?} %></p>
<p><%= f.label :email %><br />
<%= f.email_field :email %></p>
<% if action_name == "new" %>
<p><%= f.label :password, "New password" %><br />
<%= f.password_field :password %></p>
<p><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></p>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

View File

@@ -0,0 +1,23 @@
<%= form_for(@user) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<p><%= f.label :password, "New password" %><br />
<%= f.password_field :password %></p>
<p><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></p>
<div class="actions">
<%= f.submit "Change password" %>
</div>
<% end %>

7
app/views/users/edit.html.erb Executable file
View File

@@ -0,0 +1,7 @@
<h2>Edit user</h2>
<%= render 'form' %>
<p></p>
<%= render 'passwords' %>
<%= link_to 'All users', users_path %>

36
app/views/users/index.html.erb Executable file
View File

@@ -0,0 +1,36 @@
<h1>All Users</h1>
<table id="users">
<thead>
<tr>
<th>Username</th>
<th>Email</th>
<th>Login Count</th>
<th>Last Sign In</th>
<th>Admin</th>
<th>Created At</th>
<th>Last Edited</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% @users.each do |user| %>
<tr>
<th><%= user.username %></th>
<th><%= user.email %></th>
<th><%= user.sign_in_count %></th>
<th><%if user.last_sign_in_at.blank? %>Never logged in<% else %><%= time_ago_in_words(user.last_sign_in_at.to_datetime)+' ago' %><% end %></th>
<th><%= user.admin? %></th>
<th><%= user.created_at.to_s(:datetime).downcase %></th>
<th><%= user.updated_at.to_s(:datetime).downcase %></th>
<th><%= link_to "Edit", edit_user_path(user) %></th>
<th><%= link_to "Delete", user, :method => :delete, :confirm => "Are you sure?" %></th>
</tr>
<% end %>
</tbody>
</table>
<p><%= link_to "New User", new_user_path %></p>

5
app/views/users/new.html.erb Executable file
View File

@@ -0,0 +1,5 @@
<h2>Sign up</h2>
<%= render 'form' %>
<%= link_to 'All users', users_path %>

2
app/views/users/show.html.erb Executable file
View File

@@ -0,0 +1,2 @@
<p><%= @user.username %></p>
<p><%= @user.email %></p>

View File

@@ -1,4 +1,6 @@
# This file is used by Rack-based servers to start the application. # This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__) require ::File.expand_path('../config/environment', __FILE__)
run Community::Application map "/horses" do
run Community::Application
end

View File

@@ -2,9 +2,12 @@ require File.expand_path('../boot', __FILE__)
require 'rails/all' require 'rails/all'
# If you have a Gemfile, require the gems listed there, including any gems if defined?(Bundler)
# you've limited to :test, :development, or :production. # If you precompile assets before deploying to production, use this line
Bundler.require(:default, Rails.env) if defined?(Bundler) Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
module Community module Community
class Application < Rails::Application class Application < Rails::Application
@@ -30,13 +33,32 @@ module Community
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de # config.i18n.default_locale = :de
# JavaScript files you want as :defaults (application.js is always included).
# config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
# Configure the default encoding used in templates for Ruby 1.9. # Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8" config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file. # Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password] config.filter_parameters += [:password]
# Enable escaping HTML in JSON.
config.active_support.escape_html_entities_in_json = true
# Use SQL instead of Active Record's schema dumper when creating the 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
# Enforce whitelist mode for mass assignment.
# This will create an empty whitelist of attributes available for mass-assignment for all models
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
# parameters by using an attr_accessible or attr_protected declaration.
config.active_record.whitelist_attributes = true
# Enable the asset pipeline
config.assets.enabled = true
config.assets.prefix = "/horses/assets"
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
end end
end end

View File

@@ -1,22 +1,23 @@
# SQLite version 3.x
# gem install sqlite3
development: development:
adapter: sqlite3 adapter: mysql2
database: db/development.sqlite3 database: forum/dev
pool: 5 host: localhost
timeout: 5000 username: forum
password: forum
# Warning: The database defined as "test" will be erased and # Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake". # re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production. # Do not set this db to the same as development or production.
test: test:
adapter: sqlite3 adapter: mysql2
database: db/test.sqlite3 database: forum/test
pool: 5 host: localhost
timeout: 5000 username: forum
password: forum
production: production:
adapter: sqlite3 adapter: mysql2
database: db/production.sqlite3 database: forum
pool: 5 host: localhost
timeout: 5000 username: forum
password: forum

View File

@@ -3,7 +3,7 @@ Community::Application.configure do
# In the development environment your application's code is reloaded on # In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development # 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. # since you don't have to restart the web server when you make code changes.
config.cache_classes = false config.cache_classes = false
# Log error messages when you accidentally call methods on nil. # Log error messages when you accidentally call methods on nil.
@@ -11,7 +11,6 @@ Community::Application.configure do
# Show full error reports and disable caching # Show full error reports and disable caching
config.consider_all_requests_local = true config.consider_all_requests_local = true
config.action_view.debug_rjs = true
config.action_controller.perform_caching = false config.action_controller.perform_caching = false
# Don't care if the mailer can't send # Don't care if the mailer can't send
@@ -22,5 +21,17 @@ Community::Application.configure do
# Only use best-standards-support built into browsers # Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin config.action_dispatch.best_standards_support = :builtin
end
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
end

View File

@@ -1,7 +1,6 @@
Community::Application.configure do Community::Application.configure do
# Settings specified here will take precedence over those in config/application.rb # Settings specified here will take precedence over those in config/application.rb
# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests # Code is not reloaded between requests
config.cache_classes = true config.cache_classes = true
@@ -9,31 +8,46 @@ Community::Application.configure do
config.consider_all_requests_local = false config.consider_all_requests_local = false
config.action_controller.perform_caching = true config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
# Defaults to nil and saved in location specified by config.assets.prefix
# config.assets.manifest = YOUR_PATH
# Specifies the header that your server uses for sending files # Specifies the header that your server uses for sending files
config.action_dispatch.x_sendfile_header = "X-Sendfile" # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
# For nginx: # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # config.force_ssl = true
# 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) # See everything in the log (default is :info)
# config.log_level = :debug # config.log_level = :debug
# Prepend all log lines with the following tags
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups # Use a different logger for distributed setups
# config.logger = SyslogLogger.new # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production # Use a different cache store in production
# config.cache_store = :mem_cache_store # config.cache_store = :mem_cache_store
# Disable Rails's static asset server # Enable serving of images, stylesheets, and JavaScripts from an 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" # config.action_controller.asset_host = "http://assets.example.com"
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )
# Disable delivery errors, bad email addresses will be ignored # Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false # config.action_mailer.raise_delivery_errors = false
@@ -46,4 +60,8 @@ Community::Application.configure do
# Send deprecation notices to registered listeners # Send deprecation notices to registered listeners
config.active_support.deprecation = :notify config.active_support.deprecation = :notify
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5
end end

View File

@@ -7,7 +7,11 @@ Community::Application.configure do
# and recreated between test runs. Don't rely on the data there! # and recreated between test runs. Don't rely on the data there!
config.cache_classes = true config.cache_classes = true
# Log error messages when you accidentally call methods on nil. # Configure static asset server for tests with Cache-Control for performance
config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"
# Log error messages when you accidentally call methods on nil
config.whiny_nils = true config.whiny_nils = true
# Show full error reports and disable caching # Show full error reports and disable caching
@@ -25,10 +29,8 @@ Community::Application.configure do
# ActionMailer::Base.deliveries array. # ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test config.action_mailer.delivery_method = :test
# Use SQL instead of Active Record's schema dumper when creating the test database. # Raise exception on mass assignment protection for Active Record models
# This is necessary if your schema can't be completely dumped by the schema dumper, config.active_record.mass_assignment_sanitizer = :strict
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql
# Print deprecation notices to the stderr # Print deprecation notices to the stderr
config.active_support.deprecation = :stderr config.active_support.deprecation = :stderr

View File

@@ -1,8 +1,9 @@
# Use this hook to configure devise mailer, warden hooks and so forth. The first # Use this hook to configure devise mailer, warden hooks and so forth.
# four configuration values can also be set straight in your models. # Many of these configuration options can be set straight in your model.
Devise.setup do |config| Devise.setup do |config|
# ==> Mailer Configuration # ==> Mailer Configuration
# Configure the e-mail address which will be shown in DeviseMailer. # Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com" config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
# Configure the class responsible to send e-mails. # Configure the class responsible to send e-mails.
@@ -22,7 +23,7 @@ Devise.setup do |config|
# session. If you need permissions, you should implement that in a before filter. # session. If you need permissions, you should implement that in a before filter.
# You can also supply a hash where the value is a boolean determining whether # You can also supply a hash where the value is a boolean determining whether
# or not authentication should be aborted when the value is not present. # or not authentication should be aborted when the value is not present.
config.authentication_keys = [ :username ] # config.authentication_keys = [ :email ]
# Configure parameters from the request object used for authentication. Each entry # Configure parameters from the request object used for authentication. Each entry
# given should be a request method and it will automatically be passed to the # given should be a request method and it will automatically be passed to the
@@ -42,9 +43,15 @@ Devise.setup do |config|
config.strip_whitespace_keys = [ :email ] config.strip_whitespace_keys = [ :email ]
# Tell if authentication through request.params is enabled. True by default. # Tell if authentication through request.params is enabled. True by default.
# It can be set to an array that will enable params authentication only for the
# given strategies, for example, `config.params_authenticatable = [:database]` will
# enable it only for database (email + password) authentication.
# config.params_authenticatable = true # config.params_authenticatable = true
# Tell if authentication through HTTP Basic Auth is enabled. False by default. # Tell if authentication through HTTP Basic Auth is enabled. False by default.
# It can be set to an array that will enable http authentication only for the
# given strategies, for example, `config.http_authenticatable = [:token]` will
# enable it only for token authentication.
# config.http_authenticatable = false # config.http_authenticatable = false
# If http headers should be returned for AJAX requests. True by default. # If http headers should be returned for AJAX requests. True by default.
@@ -58,22 +65,46 @@ Devise.setup do |config|
# Does not affect registerable. # Does not affect registerable.
# config.paranoid = true # config.paranoid = true
# By default Devise will store the user in session. You can skip storage for
# :http_auth and :token_auth by adding those symbols to the array below.
# Notice that if you are skipping storage for all authentication paths, you
# may want to disable generating routes to Devise's sessions controller by
# passing :skip => :sessions to `devise_for` in your config/routes.rb
config.skip_session_storage = [:http_auth]
# ==> Configuration for :database_authenticatable # ==> Configuration for :database_authenticatable
# For bcrypt, this is the cost for hashing the password and defaults to 10. If # For bcrypt, this is the cost for hashing the password and defaults to 10. If
# using other encryptors, it sets how many times you want the password re-encrypted. # using other encryptors, it sets how many times you want the password re-encrypted.
config.stretches = 10 #
# Limiting the stretches to just one in testing will increase the performance of
# your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
# a value less than 10 in other environments.
config.stretches = Rails.env.test? ? 1 : 10
# Setup a pepper to generate the encrypted password. # Setup a pepper to generate the encrypted password.
# config.pepper = "5dd1b4337169f51af2b5a506f5240280114b9d34515cf707cf6df51a16bc39f077835abf8eeb5690eba2c1721f9c6cc221cd5e85168c81a2fff3fd2e3d57e926" # config.pepper = "fc80c223a8f4cf02c191c9e55b73c4e11ac86f3f2fb9c480d7b66c3ed167d0e8762a4b76b2a36a49e9d03feedee1ed2368c83ddef2a826a633598933c65443e6"
# ==> Configuration for :confirmable # ==> Configuration for :confirmable
# The time you want to give your user to confirm his account. During this time # A period that the user is allowed to access the website even without
# he will be able to access your application without confirming. Default is 0.days # confirming his account. For instance, if set to 2.days, the user will be
# When confirm_within is zero, the user won't be able to sign in without confirming. # able to access the website for two days without confirming his account,
# You can use this to let your user access some features of your application # access will be blocked just in the third day. Default is 0.days, meaning
# without confirming the account, but blocking it after a certain period # the user cannot access the website without confirming his account.
# (ie 2 days). # config.allow_unconfirmed_access_for = 2.days
# config.confirm_within = 2.days
# A period that the user is allowed to confirm their account before their
# token becomes invalid. For example, if set to 3.days, the user can confirm
# their account within 3 days after the mail was sent, but on the fourth day
# their account can't be confirmed with the token any more.
# Default is nil, meaning there is no restriction on how long a user can take
# before confirming their account.
# config.confirm_within = 3.days
# If true, requires any email changes to be confirmed (exactly the same way as
# initial account confirmation) to be applied. Requires additional unconfirmed_email
# db field (see migrations). Until confirmed new email is stored in
# unconfirmed email column, and copied to email column on successful confirmation.
config.reconfirmable = true
# Defines which key will be used when confirming an account # Defines which key will be used when confirming an account
# config.confirmation_keys = [ :email ] # config.confirmation_keys = [ :email ]
@@ -82,32 +113,30 @@ Devise.setup do |config|
# The time the user will be remembered without asking for credentials again. # The time the user will be remembered without asking for credentials again.
# config.remember_for = 2.weeks # config.remember_for = 2.weeks
# If true, a valid remember token can be re-used between multiple browsers.
# config.remember_across_browsers = true
# If true, extends the user's remember period when remembered via cookie. # If true, extends the user's remember period when remembered via cookie.
# config.extend_remember_period = false # config.extend_remember_period = false
# If true, uses the password salt as remember token. This should be turned
# to false if you are not using database authenticatable.
config.use_salt_as_remember_token = true
# Options to be passed to the created cookie. For instance, you can set # Options to be passed to the created cookie. For instance, you can set
# :secure => true in order to force SSL only cookies. # :secure => true in order to force SSL only cookies.
# config.cookie_options = {} # config.rememberable_options = {}
# ==> Configuration for :validatable # ==> Configuration for :validatable
# Range for password length. Default is 6..128. # Range for password length. Default is 8..128.
# config.password_length = 6..128 config.password_length = 8..128
# Regex to use to validate the email address # Email regex used to validate email formats. It simply asserts that
# config.email_regexp = /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i # an one (and only one) @ exists in the given string. This is mainly
# to give user feedback and not to assert the e-mail validity.
# config.email_regexp = /\A[^@]+@[^@]+\z/
# ==> Configuration for :timeoutable # ==> Configuration for :timeoutable
# The time you want to timeout the user session without activity. After this # The time you want to timeout the user session without activity. After this
# time the user will be asked for credentials again. Default is 30 minutes. # time the user will be asked for credentials again. Default is 30 minutes.
# config.timeout_in = 30.minutes # config.timeout_in = 30.minutes
# If true, expires auth token on session timeout.
# config.expire_auth_token_on_timeout = false
# ==> Configuration for :lockable # ==> Configuration for :lockable
# Defines which strategy will be used to lock an account. # Defines which strategy will be used to lock an account.
# :failed_attempts = Locks an account after a number of failed attempts to sign in. # :failed_attempts = Locks an account after a number of failed attempts to sign in.
@@ -139,7 +168,7 @@ Devise.setup do |config|
# Time interval you can reset your password with a reset password key. # Time interval you can reset your password with a reset password key.
# Don't put a too small interval or your users won't have the time to # Don't put a too small interval or your users won't have the time to
# change their passwords. # change their passwords.
config.reset_password_within = 2.hours config.reset_password_within = 6.hours
# ==> Configuration for :encryptable # ==> Configuration for :encryptable
# Allow you to use another encryption algorithm besides bcrypt (default). You can use # Allow you to use another encryption algorithm besides bcrypt (default). You can use
@@ -153,10 +182,6 @@ Devise.setup do |config|
# Defines name of the authentication token params key # Defines name of the authentication token params key
# config.token_authentication_key = :auth_token # config.token_authentication_key = :auth_token
# If true, authentication through token does not store user in session and needs
# to be supplied on each request. Useful if you are using the token as API token.
# config.stateless_token = false
# ==> Scopes configuration # ==> Scopes configuration
# Turn scoped views on. Before rendering "sessions/new", it will first check for # Turn scoped views on. Before rendering "sessions/new", it will first check for
# "users/sessions/new". It's turned off by default because it's slower if you # "users/sessions/new". It's turned off by default because it's slower if you
@@ -167,9 +192,8 @@ Devise.setup do |config|
# devise role declared in your routes (usually :user). # devise role declared in your routes (usually :user).
# config.default_scope = :user # config.default_scope = :user
# Configure sign_out behavior. # Set this configuration to false if you want /users/sign_out to sign out
# Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope). # only the current scope. By default, Devise signs out all scopes.
# The default is true, which means any logout action will sign out all active scopes.
# config.sign_out_all_scopes = true # config.sign_out_all_scopes = true
# ==> Navigation configuration # ==> Navigation configuration
@@ -180,9 +204,8 @@ Devise.setup do |config|
# If you have any extra navigational formats, like :iphone or :mobile, you # If you have any extra navigational formats, like :iphone or :mobile, you
# should add them to the navigational formats lists. # should add them to the navigational formats lists.
# #
# The :"*/*" and "*/*" formats below is required to match Internet # The "*/*" below is required to match Internet Explorer requests.
# Explorer requests. # config.navigational_formats = ["*/*", :html]
# config.navigational_formats = [:"*/*", "*/*", :html]
# The default HTTP method used to sign out a resource. Default is :delete. # The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = :delete config.sign_out_via = :delete
@@ -197,8 +220,21 @@ Devise.setup do |config|
# change the failure app, you can configure them inside the config.warden block. # change the failure app, you can configure them inside the config.warden block.
# #
# config.warden do |manager| # config.warden do |manager|
# manager.failure_app = AnotherApp
# manager.intercept_401 = false # manager.intercept_401 = false
# manager.default_strategies(:scope => :user).unshift :some_external_strategy # manager.default_strategies(:scope => :user).unshift :some_external_strategy
# end # end
# ==> Mountable engine configurations
# When using Devise inside an engine, let's call it `MyEngine`, and this engine
# is mountable, there are some extra configurations to be taken into account.
# The following options are available, assuming the engine is mounted as:
#
# mount MyEngine, at: "/my_engine"
#
# The router that invoked `devise_for`, in the example above, would be:
# config.router_name = :my_engine
#
# When using omniauth, Devise cannot automatically set Omniauth path,
# so you need to do it manually. For the users scope, it would be:
# config.omniauth_path_prefix = "/my_engine/users/auth"
end end

View File

@@ -8,3 +8,8 @@
# inflect.irregular 'person', 'people' # inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep ) # inflect.uncountable %w( fish sheep )
# end # end
#
# These inflection rules are supported but not enabled by default:
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.acronym 'RESTful'
# end

View File

@@ -4,4 +4,4 @@
# If you change this key, all old signed cookies will become invalid! # If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random, # Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks. # no regular words or you'll be exposed to dictionary attacks.
Community::Application.config.secret_token = '3d6c4640f85fbdc9a430afb4021d42b2e2c2a4e5fc4c051eda410ab04b0c43789b4ba06a51f54007ad473e31c6255f3423345e12ecb896a19ef61d07f700aa42' Community::Application.config.secret_token = 'e699c294d45c10c4d9042c2d00607a207e818ed9b58985549d6e01465bf859309529c3a8f79e2d91cf322a806230d919cf0dc4e86c0d34790f73288787b2ffb0'

View File

@@ -1,8 +1,8 @@
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
Community::Application.config.session_store :cookie_store, :key => '_community_session' Community::Application.config.session_store :cookie_store, key: '_forum_session'
# Use the database for sessions instead of the cookie-based default, # Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information # which shouldn't be used to store highly confidential information
# (create the session table with "rails generate session_migration") # (create the session table with "rails generate session_migration")
# Community::Application.config.session_store :active_record_store # Forum::Application.config.session_store :active_record_store

View File

@@ -0,0 +1,14 @@
# Be sure to restart your server when you modify this file.
#
# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
wrap_parameters format: [:json]
end
# Disable root element in JSON by default.
ActiveSupport.on_load(:active_record) do
self.include_root_in_json = false
end

View File

@@ -1,4 +1,4 @@
# Additional translations at http://github.com/plataformatec/devise/wiki/I18n # Additional translations at https://github.com/plataformatec/devise/wiki/I18n
en: en:
errors: errors:
@@ -10,6 +10,7 @@ en:
not_saved: not_saved:
one: "1 error prohibited this %{resource} from being saved:" one: "1 error prohibited this %{resource} from being saved:"
other: "%{count} errors prohibited this %{resource} from being saved:" other: "%{count} errors prohibited this %{resource} from being saved:"
confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one"
devise: devise:
failure: failure:
@@ -17,6 +18,7 @@ en:
unauthenticated: 'You need to sign in or sign up before continuing.' unauthenticated: 'You need to sign in or sign up before continuing.'
unconfirmed: 'You have to confirm your account before continuing.' unconfirmed: 'You have to confirm your account before continuing.'
locked: 'Your account is locked.' locked: 'Your account is locked.'
not_found_in_database: 'Invalid email or password.'
invalid: 'Invalid email or password.' invalid: 'Invalid email or password.'
invalid_token: 'Invalid authentication token.' invalid_token: 'Invalid authentication token.'
timeout: 'Your session expired, please sign in again to continue.' timeout: 'Your session expired, please sign in again to continue.'
@@ -27,23 +29,28 @@ en:
passwords: passwords:
send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.' send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
updated: 'Your password was changed successfully. You are now signed in.' updated: 'Your password was changed successfully. You are now signed in.'
send_paranoid_instructions: "If your e-mail exists on our database, you will receive a password recovery link on your e-mail" updated_not_active: 'Your password was changed successfully.'
send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
confirmations: confirmations:
send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.' send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
send_paranoid_instructions: 'If your e-mail exists on our database, you will receive an email with instructions about how to confirm your account in a few minutes.' send_paranoid_instructions: 'If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes.'
confirmed: 'Your account was successfully confirmed. You are now signed in.' confirmed: 'Your account was successfully confirmed. You are now signed in.'
registrations: registrations:
signed_up: 'Welcome! You have signed up successfully.' signed_up: 'Welcome! You have signed up successfully.'
inactive_signed_up: 'You have signed up successfully. However, we could not sign you in because your account is %{reason}.' signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
updated: 'You updated your account successfully.' updated: 'You updated your account successfully.'
update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.' destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
unlocks: unlocks:
send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.' send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
unlocked: 'Your account was successfully unlocked. You are now signed in.' unlocked: 'Your account has been unlocked successfully. Please sign in to continue.'
send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.' send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
omniauth_callbacks: omniauth_callbacks:
success: 'Successfully authorized from %{kind} account.' success: 'Successfully authenticated from %{kind} account.'
failure: 'Could not authorize you from %{kind} because "%{reason}".' failure: 'Could not authenticate you from %{kind} because "%{reason}".'
mailer: mailer:
confirmation_instructions: confirmation_instructions:
subject: 'Confirmation instructions' subject: 'Confirmation instructions'

View File

@@ -1,8 +1,5 @@
# Sample localization file for English. Add more files in this directory for other locales. # Sample localization file for English. Add more files in this directory for other locales.
# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
en: en:
time: hello: "Hello world"
formats:
default: "%B %d, %Y @ %I:%M %p"
joined: "%B %d, %Y"

View File

@@ -9,62 +9,9 @@ Community::Application.routes.draw do
end end
devise_for :users devise_for :users
scope "/admin" do
resources :users
end
root :to => 'categories#index', :via => :get root :to => 'categories#index', :via => :get
# The priority is based upon order of creation:
# first created -> highest priority.
# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)
# Sample resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Sample resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Sample resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Sample resource route with more complex sub-resources
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', :on => :collection
# end
# end
# Sample resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
# root :to => "welcome#index"
# See how all your routes lay out with "rake routes"
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id(.:format)))'
end end

View File

@@ -1,16 +1,43 @@
class DeviseCreateUsers < ActiveRecord::Migration class DeviseCreateUsers < ActiveRecord::Migration
def self.up def self.up
create_table(:users) do |t| create_table(:users) do |t|
t.database_authenticatable :null => false ## Database authenticatable
t.recoverable t.string :email, :null => false, :default => ""
t.rememberable t.string :encrypted_password, :null => false, :default => ""
t.trackable
# t.encryptable ## Recoverable
# t.confirmable t.string :reset_password_token
# t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both t.datetime :reset_password_sent_at
# t.token_authenticatable
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, :default => 0
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## Encryptable
# t.string :password_salt
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
# Token authenticatable
# t.string :authentication_token
## Invitable
# t.string :invitation_token
t.timestamps t.timestamps
end end

View File

@@ -0,0 +1,9 @@
class AddIsAdminToUsers < ActiveRecord::Migration
def self.up
add_column :users, :is_admin, :boolean
end
def self.down
remove_column :users, :is_admin
end
end

View File

@@ -1,3 +1,4 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead # This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to # of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition. # incrementally modify your database, and then regenerate this schema definition.
@@ -10,14 +11,14 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20110808221332) do ActiveRecord::Schema.define(:version => 20130114162614) do
create_table "categories", :force => true do |t| create_table "categories", :force => true do |t|
t.string "title" t.string "title"
t.boolean "state", :default => true t.boolean "state", :default => true
t.integer "position", :default => 0 t.integer "position", :default => 0
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
end end
create_table "forums", :force => true do |t| create_table "forums", :force => true do |t|
@@ -28,8 +29,8 @@ ActiveRecord::Schema.define(:version => 20110808221332) do
t.integer "posts_count", :default => 0 t.integer "posts_count", :default => 0
t.integer "position", :default => 0 t.integer "position", :default => 0
t.integer "category_id" t.integer "category_id"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
end end
create_table "posts", :force => true do |t| create_table "posts", :force => true do |t|
@@ -37,8 +38,8 @@ ActiveRecord::Schema.define(:version => 20110808221332) do
t.integer "forum_id" t.integer "forum_id"
t.integer "topic_id" t.integer "topic_id"
t.integer "user_id" t.integer "user_id"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
end end
create_table "topics", :force => true do |t| create_table "topics", :force => true do |t|
@@ -49,13 +50,13 @@ ActiveRecord::Schema.define(:version => 20110808221332) do
t.integer "posts_count" t.integer "posts_count"
t.integer "forum_id" t.integer "forum_id"
t.integer "user_id" t.integer "user_id"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
end end
create_table "users", :force => true do |t| create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false t.string "encrypted_password", :default => "", :null => false
t.string "reset_password_token" t.string "reset_password_token"
t.datetime "reset_password_sent_at" t.datetime "reset_password_sent_at"
t.datetime "remember_created_at" t.datetime "remember_created_at"
@@ -64,11 +65,12 @@ ActiveRecord::Schema.define(:version => 20110808221332) do
t.datetime "last_sign_in_at" t.datetime "last_sign_in_at"
t.string "current_sign_in_ip" t.string "current_sign_in_ip"
t.string "last_sign_in_ip" t.string "last_sign_in_ip"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.integer "topics_count", :default => 0 t.integer "topics_count", :default => 0
t.integer "posts_count", :default => 0 t.integer "posts_count", :default => 0
t.string "username" t.string "username"
t.boolean "is_admin"
end end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true add_index "users", ["email"], :name => "index_users_on_email", :unique => true

11
forum.conf Executable file
View File

@@ -0,0 +1,11 @@
ProxyPass /forum balancer://forumcluster
ProxyPassReverse /forum balancer://forumcluster
<Proxy balancer://forumcluster>
BalancerMember http://127.0.0.1:3000/forum
BalancerMember http://127.0.0.1:3001/forum
BalancerMember http://127.0.0.1:3002/forum
BalancerMember http://127.0.0.1:3003/forum
Order deny,allow
Allow from all
</Proxy>

21
forum.service Normal file
View File

@@ -0,0 +1,21 @@
[Unit]
Description=Forum server
After=syslog.target
After=network.target
[Service]
Type=forking
User=forum
Group=forum
SyslogIdentifier=forum-unicorn
ExecStart=/opt/forum/.gem/ruby/1.9.1/bin/unicorn -E production -c /opt/forum/forum/unicorn.ru -D
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
WorkingDirectory=/opt/forum/forum
PIDFile=/tmp/forum.pid
# Give a reasonable amount of time for the server to start up/shut down
#TimeoutSec=300
[Install]
WantedBy=multi-user.target

0
lib/assets/.gitkeep Normal file
View File

0
log/.gitkeep Normal file
View File

0
test/fixtures/.gitkeep vendored Normal file
View File

View File

@@ -1,11 +0,0 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value

0
test/functional/.gitkeep Normal file
View File

View File

View File

@@ -1,8 +1,11 @@
require 'test_helper' require 'test_helper'
require 'rails/performance_test_help' require 'rails/performance_test_help'
# Profiling results for each test method are written to tmp/performance.
class BrowsingTest < ActionDispatch::PerformanceTest class BrowsingTest < ActionDispatch::PerformanceTest
# Refer to the documentation for all available options
# self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
# :output => 'tmp/performance', :formats => [:flat] }
def test_homepage def test_homepage
get '/' get '/'
end end

0
test/unit/.gitkeep Normal file
View File

View File

@@ -1,8 +0,0 @@
require 'test_helper'
class UserTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end

19
unicorn.ru Executable file
View File

@@ -0,0 +1,19 @@
working_directory "/opt/horse_forum/forum/"
pid "/tmp/horse_forum.pid"
preload_app true
timeout 60
worker_processes 4
listen "/tmp/horseforum.sock"
stderr_path('/opt/horse_forum/unicorn.log')
GC.respond_to?(:copy_on_write_friendly=) and GC.copy_on_write_friendly = true
after_fork do |server, worker|
#start the worker on port 4000, 4001, 4002 etc...
addr = "0.0.0.0:#{3000 + worker.nr}"
# infinite tries to start the worker
server.listen(addr, :tries => -1, :delay => -1, :backlog => 128)
#Drop privileges if running as root
worker.user('nobody', 'nobody') if Process.euid == 0
end

0
vendor/assets/javascripts/.gitkeep vendored Normal file
View File

0
vendor/assets/stylesheets/.gitkeep vendored Normal file
View File