Skip to content

Commit d7794a9

Browse files
committed
Merge pull request #72 from dominic/rails3
Generators, useful gems and scaffolding
2 parents af4d271 + 841ba1a commit d7794a9

38 files changed

Lines changed: 738 additions & 4 deletions

Gemfile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ gem 'rails', '3.1.0.rc6'
44
gem 'sqlite3'
55
gem 'json'
66

7-
gem 'haml'
7+
gem 'haml-rails'
88
gem 'jquery-rails'
99
gem 'mongo_mapper'
1010
gem 'bson_ext'
@@ -20,14 +20,21 @@ end
2020
gem 'jnunemaker-validatable', '>= 1.8.4' # Required by mm-devise
2121
gem 'devise', '>= 1.2'
2222
gem 'mm-devise', '>= 1.2'
23+
gem 'cancan'
2324

25+
gem 'inherited_resources'
26+
gem 'simple_form'
2427
gem "semantic_menu", :git => "git://github.com/michaek/semantic_menu.git"
2528

26-
# Use unicorn as the web server
27-
gem 'unicorn'
29+
group :development do
30+
# Use unicorn as the web server
31+
gem 'unicorn'
32+
end
33+
2834

2935
group :development, :test do
3036
gem 'fabrication'
3137
gem 'rspec-rails'
3238
gem 'cucumber-rails'
3339
end
40+
gem "mocha", :group => :test

Gemfile.lock

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ GEM
4141
bson (1.3.1)
4242
bson_ext (1.3.1)
4343
builder (3.0.0)
44+
cancan (1.6.5)
4445
capybara (1.0.1)
4546
mime-types (>= 1.16)
4647
nokogiri (>= 1.3.3)
@@ -80,8 +81,17 @@ GEM
8081
gherkin (2.4.16)
8182
json (>= 1.4.6)
8283
haml (3.1.2)
84+
haml-rails (0.3.4)
85+
actionpack (~> 3.0)
86+
activesupport (~> 3.0)
87+
haml (~> 3.0)
88+
railties (~> 3.0)
89+
has_scope (0.5.1)
8390
hike (1.2.1)
8491
i18n (0.6.0)
92+
inherited_resources (1.2.2)
93+
has_scope (~> 0.5.0)
94+
responders (~> 0.6.0)
8595
jnunemaker-validatable (1.8.4)
8696
activesupport (>= 2.3.4)
8797
jquery-rails (1.0.13)
@@ -98,6 +108,7 @@ GEM
98108
mm-devise (1.3)
99109
devise (>= 1.2)
100110
mongo_mapper (>= 0.9.0)
111+
mocha (0.9.12)
101112
mongo (1.3.1)
102113
bson (>= 1.3.1)
103114
mongo_mapper (0.9.1)
@@ -137,6 +148,7 @@ GEM
137148
raindrops (0.7.0)
138149
rake (0.9.2)
139150
rdoc (3.9.4)
151+
responders (0.6.4)
140152
rspec (2.6.0)
141153
rspec-core (~> 2.6.0)
142154
rspec-expectations (~> 2.6.0)
@@ -161,6 +173,9 @@ GEM
161173
ffi (>= 1.0.7)
162174
json_pure
163175
rubyzip
176+
simple_form (1.4.2)
177+
actionpack (~> 3.0)
178+
activemodel (~> 3.0)
164179
sprockets (2.0.0.beta.15)
165180
hike (~> 1.2)
166181
rack (~> 1.0)
@@ -190,20 +205,24 @@ PLATFORMS
190205

191206
DEPENDENCIES
192207
bson_ext
208+
cancan
193209
coffee-rails (~> 3.1.0.rc)
194210
cucumber-rails
195211
devise (>= 1.2)
196212
fabrication
197-
haml
213+
haml-rails
214+
inherited_resources
198215
jnunemaker-validatable (>= 1.8.4)
199216
jquery-rails
200217
json
201218
mm-devise (>= 1.2)
219+
mocha
202220
mongo_mapper
203221
rails (= 3.1.0.rc6)
204222
rspec-rails
205223
sass-rails (~> 3.1.0.rc)
206224
semantic_menu!
225+
simple_form
207226
sqlite3
208227
uglifier
209228
unicorn
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Place all the behaviors and hooks related to the matching controller here.
2+
# All this logic will automatically be available in application.js.
3+
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Place all the styles related to the Questions controller here.
2+
// They will automatically be included in application.css.
3+
// You can use Sass (SCSS) here: http://sass-lang.com/
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
body {
2+
background-color: #fff;
3+
color: #333;
4+
font-family: verdana, arial, helvetica, sans-serif;
5+
font-size: 13px;
6+
line-height: 18px; }
7+
8+
p, ol, ul, td {
9+
font-family: verdana, arial, helvetica, sans-serif;
10+
font-size: 13px;
11+
line-height: 18px; }
12+
13+
pre {
14+
background-color: #eee;
15+
padding: 10px;
16+
font-size: 11px; }
17+
18+
a {
19+
color: #000;
20+
&:visited {
21+
color: #666; }
22+
&:hover {
23+
color: #fff;
24+
background-color: #000; } }
25+
26+
div {
27+
&.field, &.actions {
28+
margin-bottom: 10px; } }
29+
30+
#notice {
31+
color: green; }
32+
33+
.field_with_errors {
34+
padding: 2px;
35+
background-color: red;
36+
display: table; }
37+
38+
#error_explanation {
39+
width: 450px;
40+
border: 2px solid red;
41+
padding: 7px;
42+
padding-bottom: 0;
43+
margin-bottom: 20px;
44+
background-color: #f0f0f0;
45+
h2 {
46+
text-align: left;
47+
font-weight: bold;
48+
padding: 5px 5px 5px 15px;
49+
font-size: 12px;
50+
margin: -7px;
51+
margin-bottom: 0px;
52+
background-color: #c00;
53+
color: #fff; }
54+
ul li {
55+
font-size: 12px;
56+
list-style: square; } }
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class InheritedController < ApplicationController
2+
inherit_resources
3+
4+
before_filter :form_url, :only => [:new, :create, :edit, :update]
5+
6+
# Set form url instance variable correctly depending on action
7+
def form_url
8+
9+
# this line is to fix a bug that I was getting.
10+
# if you remove it, maybe try commenting it out instead.
11+
# if you get this bug:
12+
# undefined method `model_name' for NilClass:Class
13+
# ...
14+
# app/controllers/inherited_controller.rb:39:in `form_url'
15+
#
16+
# etc, then try adding it back in.
17+
begin
18+
resource.inspect
19+
rescue
20+
end
21+
# end of bug fix.
22+
23+
24+
if ['new','create'].include? params[:action]
25+
@form_url = collection_path
26+
elsif
27+
@form_url = resource_path
28+
end
29+
end
30+
31+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class QuestionsController < InheritedController
2+
3+
defaults :resource_class => Question
4+
5+
end

app/helpers/questions_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module QuestionsHelper
2+
end

app/models/ability.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Ability
2+
include CanCan::Ability
3+
4+
def initialize(user)
5+
# Define abilities for the passed in user here. For example:
6+
#
7+
# user ||= User.new # guest user (not logged in)
8+
# if user.admin?
9+
# can :manage, :all
10+
# else
11+
# can :read, :all
12+
# end
13+
#
14+
# The first argument to `can` is the action you are giving the user permission to do.
15+
# If you pass :manage it will apply to every action. Other common actions here are
16+
# :read, :create, :update and :destroy.
17+
#
18+
# The second argument is the resource the user can perform the action on. If you pass
19+
# :all it will apply to every resource. Otherwise pass a Ruby class of the resource.
20+
#
21+
# The third argument is an optional hash of conditions to further filter the objects.
22+
# For example, here the user can only update published articles.
23+
#
24+
# can :update, Article, :published => true
25+
#
26+
# See the wiki for details: https://github.com/ryanb/cancan/wiki/Defining-Abilities
27+
end
28+
end

app/models/question.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Question
2+
include MongoMapper::Document
3+
4+
key :title, String
5+
key :description, String
6+
7+
end

0 commit comments

Comments
 (0)