Skip to content

Commit 5e2f834

Browse files
committed
added inherited_resources, cancan, simple_form
1 parent 09ea595 commit 5e2f834

15 files changed

Lines changed: 261 additions & 2 deletions

File tree

Gemfile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +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

2425
gem 'inherited_resources'
26+
gem 'simple_form'
2527
gem "semantic_menu", :git => "git://github.com/michaek/semantic_menu.git"
2628

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

3035
group :development, :test do
3136
gem 'fabrication'
3237
gem 'rspec-rails'
3338
gem 'cucumber-rails'
3439
end
40+
gem "mocha", :group => :test

Gemfile.lock

Lines changed: 8 additions & 0 deletions
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)
@@ -107,6 +108,7 @@ GEM
107108
mm-devise (1.3)
108109
devise (>= 1.2)
109110
mongo_mapper (>= 0.9.0)
111+
mocha (0.9.12)
110112
mongo (1.3.1)
111113
bson (>= 1.3.1)
112114
mongo_mapper (0.9.1)
@@ -171,6 +173,9 @@ GEM
171173
ffi (>= 1.0.7)
172174
json_pure
173175
rubyzip
176+
simple_form (1.4.2)
177+
actionpack (~> 3.0)
178+
activemodel (~> 3.0)
174179
sprockets (2.0.0.beta.15)
175180
hike (~> 1.2)
176181
rack (~> 1.0)
@@ -200,6 +205,7 @@ PLATFORMS
200205

201206
DEPENDENCIES
202207
bson_ext
208+
cancan
203209
coffee-rails (~> 3.1.0.rc)
204210
cucumber-rails
205211
devise (>= 1.2)
@@ -210,11 +216,13 @@ DEPENDENCIES
210216
jquery-rails
211217
json
212218
mm-devise (>= 1.2)
219+
mocha
213220
mongo_mapper
214221
rails (= 3.1.0.rc6)
215222
rspec-rails
216223
sass-rails (~> 3.1.0.rc)
217224
semantic_menu!
225+
simple_form
218226
sqlite3
219227
uglifier
220228
unicorn

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

config/initializers/simple_form.rb

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Use this setup block to configure all options available in SimpleForm.
2+
SimpleForm.setup do |config|
3+
# Components used by the form builder to generate a complete input. You can remove
4+
# any of them, change the order, or even add your own components to the stack.
5+
# config.components = [ :placeholder, :label_input, :hint, :error ]
6+
7+
# Default tag used on hints.
8+
# config.hint_tag = :span
9+
10+
# CSS class to add to all hint tags.
11+
# config.hint_class = :hint
12+
13+
# CSS class used on errors.
14+
# config.error_class = :error
15+
16+
# Default tag used on errors.
17+
# config.error_tag = :span
18+
19+
# Method used to tidy up errors.
20+
# config.error_method = :first
21+
22+
# Default tag used for error notification helper.
23+
# config.error_notification_tag = :p
24+
25+
# CSS class to add for error notification helper.
26+
# config.error_notification_class = :error_notification
27+
28+
# ID to add for error notification helper.
29+
# config.error_notification_id = nil
30+
31+
# You can wrap all inputs in a pre-defined tag.
32+
# config.wrapper_tag = :div
33+
34+
# CSS class to add to all wrapper tags.
35+
# config.wrapper_class = :input
36+
37+
# CSS class to add to the wrapper if the field has errors.
38+
# config.wrapper_error_class = :field_with_errors
39+
40+
# You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
41+
# config.collection_wrapper_tag = nil
42+
43+
# You can wrap each item in a collection of radio/check boxes with a tag, defaulting to span.
44+
# config.item_wrapper_tag = :span
45+
46+
# Series of attempts to detect a default label method for collection.
47+
# config.collection_label_methods = [ :to_label, :name, :title, :to_s ]
48+
49+
# Series of attempts to detect a default value method for collection.
50+
# config.collection_value_methods = [ :id, :to_s ]
51+
52+
# How the label text should be generated altogether with the required text.
53+
# config.label_text = lambda { |label, required| "#{required} #{label}" }
54+
55+
# You can define the class to use on all labels. Default is nil.
56+
# config.label_class = nil
57+
58+
# You can define the class to use on all forms. Default is simple_form.
59+
# config.form_class = :simple_form
60+
61+
# Whether attributes are required by default (or not). Default is true.
62+
# config.required_by_default = true
63+
64+
# Tell browsers whether to use default HTML5 validations (novalidate option).
65+
# Default is enabled.
66+
# config.browser_validations = true
67+
68+
# Determines whether HTML5 types (:email, :url, :search, :tel) and attributes
69+
# (e.g. required) are used or not. True by default.
70+
# Having this on in non-HTML5 compliant sites can cause odd behavior in
71+
# HTML5-aware browsers such as Chrome.
72+
# config.html5 = true
73+
74+
# Custom mappings for input types. This should be a hash containing a regexp
75+
# to match as key, and the input type that will be used when the field name
76+
# matches the regexp as value.
77+
# config.input_mappings = { /count/ => :integer }
78+
79+
# Collection of methods to detect if a file type was given.
80+
# config.file_methods = [ :mounted_as, :file?, :public_filename ]
81+
82+
# Default priority for time_zone inputs.
83+
# config.time_zone_priority = nil
84+
85+
# Default priority for country inputs.
86+
# config.country_priority = nil
87+
88+
# Default size for text inputs.
89+
# config.default_input_size = 50
90+
91+
# When false, do not use translations for labels, hints or placeholders.
92+
# config.translate = true
93+
end

config/locales/simple_form.en.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
en:
2+
simple_form:
3+
"yes": 'Yes'
4+
"no": 'No'
5+
required:
6+
text: 'required'
7+
mark: '*'
8+
# You can uncomment the line below if you need to overwrite the whole required html.
9+
# When using html, text and mark won't be used.
10+
# html: '<abbr title="required">*</abbr>'
11+
error_notification:
12+
default_message: "Some errors were found, please take a look:"
13+
# Labels and hints examples
14+
# labels:
15+
# password: 'Password'
16+
# user:
17+
# new:
18+
# email: 'E-mail para efetuar o sign in.'
19+
# edit:
20+
# email: 'E-mail.'
21+
# hints:
22+
# username: 'User name to sign in.'
23+
# password: 'No special characters, please.'
24+

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
HacketyHackCom::Application.routes.draw do
22

3+
resources :questions
4+
35
constraints(ApiConstraint) do
46
match '/' => 'static#api_root'
57
match '/versions/newest' => 'static#newest_version', :as => "newest_version"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class CreateQuestions < ActiveRecord::Migration
2+
def self.up
3+
create_table :questions do |t|
4+
t.string :title
5+
t.text :description
6+
t.integer :user_id
7+
t.timestamps
8+
end
9+
end
10+
11+
def self.down
12+
drop_table :questions
13+
end
14+
end

lib/generators/.DS_Store

6 KB
Binary file not shown.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
require 'rails/generators/erb/scaffold/scaffold_generator'
2+
3+
module Haml
4+
module Generators
5+
class ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
6+
source_root File.expand_path("../templates", __FILE__)
7+
8+
def copy_view_files
9+
available_views.each do |view|
10+
filename = filename_with_extensions(view)
11+
template "#{view}.html.haml", File.join("app/views", controller_file_path, filename)
12+
end
13+
end
14+
15+
hook_for :form_builder, :as => :scaffold
16+
17+
def copy_form_file
18+
if options[:form_builder].nil?
19+
filename = filename_with_extensions("_form")
20+
template "_form.html.haml", File.join("app/views", controller_file_path, filename)
21+
end
22+
end
23+
24+
protected
25+
26+
def available_views
27+
%w(index edit show new _list)
28+
end
29+
30+
def handler
31+
:haml
32+
end
33+
34+
end
35+
end
36+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
%li.item
2+
= link_to list, resource_path(list)
3+
4+
- if can? :update, list
5+
= link_to 'Edit', edit_resource_path(list)
6+
- if can? :destroy, list
7+
= link_to 'Delete', resource_path(list), :confirm => 'Are you sure?', :method => :delete

0 commit comments

Comments
 (0)