Skip to content

Commit 841ba1a

Browse files
committed
added question scaffold
1 parent 5e2f834 commit 841ba1a

23 files changed

Lines changed: 463 additions & 0 deletions
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/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
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
= simple_form_for(resource, :url => @form_url) do |f|
2+
= f.error_notification
3+
4+
.inputs
5+
= f.input :title
6+
= f.input :description
7+
8+
.actions
9+
= f.button :submit
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

app/views/questions/edit.html.haml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- content_for :title do
2+
= "Editing #{resource}"
3+
4+
= render 'form'

0 commit comments

Comments
 (0)