rapidfire 2.1.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +28 -13
  3. data/app/controllers/rapidfire/attempts_controller.rb +29 -0
  4. data/app/controllers/rapidfire/questions_controller.rb +35 -34
  5. data/app/controllers/rapidfire/surveys_controller.rb +60 -0
  6. data/app/models/rapidfire/answer.rb +3 -3
  7. data/app/models/rapidfire/attempt.rb +11 -0
  8. data/app/models/rapidfire/question.rb +3 -3
  9. data/app/models/rapidfire/{question_group.rb → survey.rb} +1 -1
  10. data/app/services/rapidfire/{answer_group_builder.rb → attempt_builder.rb} +12 -12
  11. data/app/services/rapidfire/base_service.rb +1 -1
  12. data/app/services/rapidfire/question_form.rb +4 -4
  13. data/app/services/rapidfire/{question_group_results.rb → survey_results.rb} +3 -3
  14. data/app/views/rapidfire/{answer_groups → attempts}/new.html.erb +2 -2
  15. data/app/views/rapidfire/questions/_question.html.erb +2 -2
  16. data/app/views/rapidfire/questions/edit.html.erb +1 -1
  17. data/app/views/rapidfire/questions/index.html.erb +1 -1
  18. data/app/views/rapidfire/questions/new.html.erb +1 -1
  19. data/app/views/rapidfire/surveys/_form.html.erb +15 -0
  20. data/app/views/rapidfire/surveys/_survey.html.erb +18 -0
  21. data/app/views/rapidfire/{question_groups → surveys}/index.html.erb +4 -4
  22. data/app/views/rapidfire/surveys/new.html.erb +1 -0
  23. data/app/views/rapidfire/{question_groups → surveys}/results.html.erb +1 -1
  24. data/config/routes.rb +3 -3
  25. data/db/migrate/20130502170733_create_rapidfire_question_groups.rb +1 -1
  26. data/db/migrate/20130502195310_create_rapidfire_questions.rb +2 -2
  27. data/db/migrate/20130502195415_create_rapidfire_answer_groups.rb +4 -4
  28. data/db/migrate/20130502195504_create_rapidfire_answers.rb +2 -2
  29. data/lib/generators/rapidfire/templates/migrations/rename_answer_groups_and_question_groups.rb +9 -0
  30. data/lib/generators/rapidfire/upgrade_migration_generator.rb +18 -0
  31. data/lib/generators/rapidfire/views_generator.rb +4 -4
  32. data/lib/rapidfire/version.rb +1 -1
  33. data/lib/tasks/rapidfire.rake +10 -0
  34. data/spec/controllers/rapidfire/attempts_controller_spec.rb +20 -0
  35. data/spec/dummy/README.rdoc +261 -0
  36. data/spec/dummy/Rakefile +7 -0
  37. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  38. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  39. data/spec/dummy/app/controllers/application_controller.rb +11 -0
  40. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  41. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  42. data/spec/dummy/config.ru +4 -0
  43. data/spec/dummy/config/application.rb +61 -0
  44. data/spec/dummy/config/boot.rb +10 -0
  45. data/spec/dummy/config/database.yml +25 -0
  46. data/spec/dummy/config/environment.rb +5 -0
  47. data/spec/dummy/config/environments/development.rb +41 -0
  48. data/spec/dummy/config/environments/production.rb +72 -0
  49. data/spec/dummy/config/environments/test.rb +41 -0
  50. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  51. data/spec/dummy/config/initializers/inflections.rb +15 -0
  52. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  53. data/spec/dummy/config/initializers/secret_token.rb +8 -0
  54. data/spec/dummy/config/initializers/session_store.rb +8 -0
  55. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  56. data/spec/dummy/config/locales/en.yml +5 -0
  57. data/spec/dummy/config/routes.rb +4 -0
  58. data/spec/dummy/db/development.sqlite3 +0 -0
  59. data/spec/dummy/db/schema.rb +53 -0
  60. data/spec/dummy/db/test.sqlite3 +0 -0
  61. data/spec/dummy/log/development.log +394 -0
  62. data/spec/dummy/log/test.log +2380 -0
  63. data/spec/dummy/public/404.html +26 -0
  64. data/spec/dummy/public/422.html +26 -0
  65. data/spec/dummy/public/500.html +25 -0
  66. data/spec/dummy/public/favicon.ico +0 -0
  67. data/spec/dummy/script/rails +6 -0
  68. data/spec/factories/answers_factory.rb +7 -0
  69. data/spec/factories/attempts_factory.rb +5 -0
  70. data/spec/factories/questions_factory.rb +30 -0
  71. data/spec/factories/surveys_factory.rb +5 -0
  72. data/spec/features/rapidfire/answering_questions_spec.rb +55 -0
  73. data/spec/features/rapidfire/managing_questions_spec.rb +95 -0
  74. data/spec/features/rapidfire/managing_surveys_spec.rb +141 -0
  75. data/spec/models/rapidfire/answer_spec.rb +23 -0
  76. data/spec/models/rapidfire/attempt_spec.rb +9 -0
  77. data/spec/models/rapidfire/question_spec.rb +123 -0
  78. data/spec/models/rapidfire/questions/checkbox_spec.rb +90 -0
  79. data/spec/models/rapidfire/questions/date_spec.rb +78 -0
  80. data/spec/models/rapidfire/questions/numeric_spec.rb +114 -0
  81. data/spec/models/rapidfire/questions/select_spec.rb +90 -0
  82. data/spec/models/rapidfire/survey_spec.rb +11 -0
  83. data/spec/serializers/rapidfire/question_result_serializer_spec.rb +44 -0
  84. data/spec/services/rapidfire/attempt_builder_spec.rb +88 -0
  85. data/spec/services/rapidfire/question_form_spec.rb +93 -0
  86. data/spec/services/rapidfire/survey_results_spec.rb +63 -0
  87. data/spec/spec_helper.rb +68 -0
  88. data/spec/support/rapidfire/answer_spec_helper.rb +23 -0
  89. data/spec/support/rapidfire/question_spec_helper.rb +13 -0
  90. data/spec/tasks/change_delimiter_from_comma_to_srsn_spec.rb +31 -0
  91. metadata +133 -30
  92. data/app/controllers/rapidfire/answer_groups_controller.rb +0 -29
  93. data/app/controllers/rapidfire/question_groups_controller.rb +0 -59
  94. data/app/models/rapidfire/answer_group.rb +0 -11
  95. data/app/views/rapidfire/question_groups/_form.html.erb +0 -15
  96. data/app/views/rapidfire/question_groups/_question_group.html.erb +0 -18
  97. data/app/views/rapidfire/question_groups/new.html.erb +0 -1
@@ -1,6 +1,6 @@
1
1
  module Rapidfire
2
2
  class BaseService
3
- if Rails::VERSION::MAJOR == 4
3
+ if Rails::VERSION::MAJOR == 4 || Rails::VERSION::MAJOR == 5
4
4
  include ActiveModel::Model
5
5
  else
6
6
  extend ActiveModel::Naming
@@ -17,7 +17,7 @@ module Rapidfire
17
17
  result
18
18
  end
19
19
 
20
- attr_accessor :question_group, :question,
20
+ attr_accessor :survey, :question,
21
21
  :type, :question_text, :answer_options, :answer_presence,
22
22
  :answer_minimum_length, :answer_maximum_length,
23
23
  :answer_greater_than_or_equal_to, :answer_less_than_or_equal_to
@@ -27,7 +27,7 @@ module Rapidfire
27
27
  def initialize(params = {})
28
28
  from_question_to_attributes(params[:question]) if params[:question]
29
29
  super(params)
30
- @question ||= question_group.questions.new
30
+ @question ||= survey.questions.new
31
31
  end
32
32
 
33
33
  def save
@@ -53,7 +53,7 @@ module Rapidfire
53
53
 
54
54
  def to_question_params
55
55
  {
56
- :question_group => question_group,
56
+ :survey => survey,
57
57
  :question_text => question_text,
58
58
  :answer_options => answer_options,
59
59
  :validation_rules => {
@@ -68,7 +68,7 @@ module Rapidfire
68
68
 
69
69
  def from_question_to_attributes(question)
70
70
  self.type = question.type
71
- self.question_group = question.question_group
71
+ self.survey = question.survey
72
72
  self.question_text = question.question_text
73
73
  self.answer_options = question.answer_options
74
74
  self.answer_presence = question.rules[:presence]
@@ -1,6 +1,6 @@
1
1
  module Rapidfire
2
- class QuestionGroupResults < Rapidfire::BaseService
3
- attr_accessor :question_group
2
+ class SurveyResults < Rapidfire::BaseService
3
+ attr_accessor :survey
4
4
 
5
5
  # extracts question along with results
6
6
  # each entry will have the following:
@@ -9,7 +9,7 @@ module Rapidfire
9
9
  # 3. if aggregatable, return each option with value
10
10
  # 4. else return an array of all the answers given
11
11
  def extract
12
- @question_group.questions.collect do |question|
12
+ @survey.questions.collect do |question|
13
13
  results =
14
14
  case question
15
15
  when Rapidfire::Questions::Select, Rapidfire::Questions::Radio,
@@ -1,8 +1,8 @@
1
1
  <h2>Please answer these Questions</h2>
2
2
  <hr/>
3
3
 
4
- <%= form_for([@question_group, @answer_group_builder]) do |f| %>
5
- <%- @answer_group_builder.answers.each do |answer| %>
4
+ <%= form_for([@survey, @attempt_builder]) do |f| %>
5
+ <%- @attempt_builder.answers.each do |answer| %>
6
6
  <%= f.fields_for("#{answer.question.id}", answer) do |answer_form| %>
7
7
  <%= render_answer_form_helper(answer, answer_form) %>
8
8
  <% end %>
@@ -2,8 +2,8 @@
2
2
  <td><%= question.question_text %></td>
3
3
  <td>
4
4
  <ul class="horizontal-list">
5
- <li><%= link_to "Edit", [:edit, question.question_group, question] %></li>
6
- <li><%= link_to "Delete", [question.question_group, question], method: :delete %></li>
5
+ <li><%= link_to "Edit", [:edit, question.survey, question] %></li>
6
+ <li><%= link_to "Delete", [question.survey, question], method: :delete %></li>
7
7
  </ul>
8
8
  </td>
9
9
  </tr>
@@ -1 +1 @@
1
- <%= render partial: 'form', locals: { form: @question_form, url: question_group_question_path(@question_group, @question), method: :put, submit_text: 'Update Question' } %>
1
+ <%= render partial: 'form', locals: { form: @question_form, url: survey_question_path(@survey, @question), method: :put, submit_text: 'Update Question' } %>
@@ -1,6 +1,6 @@
1
1
  <h2>
2
2
  Questions
3
- <%= link_to "New Question", new_question_group_question_path(@question_group) %>
3
+ <%= link_to "New Question", new_survey_question_path(@survey) %>
4
4
  </h2>
5
5
  <hr/>
6
6
 
@@ -1 +1 @@
1
- <%= render partial: 'form', locals: { form: @question_form, url: question_group_questions_path(@question_group), method: :post, submit_text: 'Create Question' } %>
1
+ <%= render partial: 'form', locals: { form: @question_form, url: survey_questions_path(@survey), method: :post, submit_text: 'Create Question' } %>
@@ -0,0 +1,15 @@
1
+ <h3><%= survey.new_record? ? "New Survey" : "Edit Survey" %></h3>
2
+
3
+ <%= form_for survey do |f| %>
4
+ <%- if survey.errors.any? %>
5
+ <ul>
6
+ <%- survey.errors.full_messages.each do |message| %>
7
+ <li><%= message %></li>
8
+ <% end %>
9
+ </ul>
10
+ <% end %>
11
+
12
+ <%= f.label :name %>
13
+ <%= f.text_field :name %>
14
+ <%= f.submit %>
15
+ <% end %>
@@ -0,0 +1,18 @@
1
+ <tr id= "survey_<%= survey.id %>">
2
+ <td>
3
+ <% if can_administer? %>
4
+ <%= link_to survey.name, survey_questions_path(survey) %>
5
+ <% else %>
6
+ <%= survey.name %>
7
+ <% end %>
8
+ </td>
9
+ <td>
10
+ <ul class="horizontal-list">
11
+ <li><%= link_to "Answer Questions", new_survey_attempt_path(survey) %></li>
12
+ <% if can_administer? %>
13
+ <li><%= link_to "Results", [:results, survey] %></li>
14
+ <li><%= link_to "Delete", survey, method: :delete %></li>
15
+ <% end %>
16
+ </ul>
17
+ </td>
18
+ </tr>
@@ -1,7 +1,7 @@
1
1
  <h2>
2
- Question Groups
2
+ Surveys
3
3
  <% if can_administer? %>
4
- <%= link_to "New Group", new_question_group_path %>
4
+ <%= link_to "New Survey", new_survey_path %>
5
5
  <% end %>
6
6
  </h2>
7
7
  <hr/>
@@ -13,11 +13,11 @@
13
13
  </colgroup>
14
14
  <thead>
15
15
  <tr>
16
- <th>Question Group</th>
16
+ <th>Survey</th>
17
17
  <th></th>
18
18
  </tr>
19
19
  </thead>
20
20
  <tbody>
21
- <%= render partial: "question_group", collection: @question_groups %>
21
+ <%= render partial: "survey", collection: @surveys %>
22
22
  </tbody>
23
23
  </table>
@@ -0,0 +1 @@
1
+ <%= render partial: 'form', locals: {survey: @survey} %>
@@ -1,6 +1,6 @@
1
1
  <h1>Results</h1>
2
2
 
3
- <%- @question_group_results.each do |result| %>
3
+ <%- @survey_results.each do |result| %>
4
4
  <div>
5
5
  <h4><%= result.question.question_text %></h4>
6
6
  <p>
@@ -1,10 +1,10 @@
1
1
  Rapidfire::Engine.routes.draw do
2
- resources :question_groups do
2
+ resources :surveys do
3
3
  get 'results', on: :member
4
4
 
5
5
  resources :questions
6
- resources :answer_groups, only: [:new, :create]
6
+ resources :attempts, only: [:new, :create]
7
7
  end
8
8
 
9
- root :to => "question_groups#index"
9
+ root :to => "surveys#index"
10
10
  end
@@ -1,6 +1,6 @@
1
1
  class CreateRapidfireQuestionGroups < ActiveRecord::Migration
2
2
  def change
3
- create_table :rapidfire_question_groups do |t|
3
+ create_table :rapidfire_surveys do |t|
4
4
  t.string :name
5
5
  t.timestamps
6
6
  end
@@ -1,7 +1,7 @@
1
1
  class CreateRapidfireQuestions < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :rapidfire_questions do |t|
4
- t.references :question_group
4
+ t.references :survey
5
5
  t.string :type
6
6
  t.string :question_text
7
7
  t.integer :position
@@ -10,6 +10,6 @@ class CreateRapidfireQuestions < ActiveRecord::Migration
10
10
 
11
11
  t.timestamps
12
12
  end
13
- add_index :rapidfire_questions, :question_group_id
13
+ add_index :rapidfire_questions, :survey_id
14
14
  end
15
15
  end
@@ -1,12 +1,12 @@
1
1
  class CreateRapidfireAnswerGroups < ActiveRecord::Migration
2
2
  def change
3
- create_table :rapidfire_answer_groups do |t|
4
- t.references :question_group
3
+ create_table :rapidfire_attempts do |t|
4
+ t.references :survey
5
5
  t.references :user, polymorphic: true
6
6
 
7
7
  t.timestamps
8
8
  end
9
- add_index :rapidfire_answer_groups, :question_group_id
10
- add_index :rapidfire_answer_groups, [:user_id, :user_type]
9
+ add_index :rapidfire_attempts, :survey_id
10
+ add_index :rapidfire_attempts, [:user_id, :user_type]
11
11
  end
12
12
  end
@@ -1,13 +1,13 @@
1
1
  class CreateRapidfireAnswers < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :rapidfire_answers do |t|
4
- t.references :answer_group
4
+ t.references :attempt
5
5
  t.references :question
6
6
  t.text :answer_text
7
7
 
8
8
  t.timestamps
9
9
  end
10
- add_index :rapidfire_answers, :answer_group_id
10
+ add_index :rapidfire_answers, :attempt_id
11
11
  add_index :rapidfire_answers, :question_id
12
12
  end
13
13
  end
@@ -0,0 +1,9 @@
1
+ class RenameAnswerGroupsAndQuestionGroups < ActiveRecord::Migration
2
+ def change
3
+ rename_table :rapidfire_answer_groups, :rapidfire_attempts
4
+ rename_table :rapidfire_question_groups, :rapidfire_surveys
5
+ rename_column :rapidfire_answers, :answer_group_id, :attempt_id
6
+ rename_column :rapidfire_attempts, :question_group_id, :survey_id
7
+ rename_column :rapidfire_questions, :question_group_id, :survey_id
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ module Rapidfire
2
+ module Generators
3
+ class UpgradeMigrationGenerator < ::Rails::Generators::Base
4
+ include Rails::Generators::Migration
5
+
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ def self.next_migration_number(dir)
9
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
10
+ end
11
+
12
+ def copy_migrations
13
+ migration_template "migrations/rename_answer_groups_and_question_groups.rb", "db/migrate/rename_answer_groups_and_question_groups.rb"
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -4,13 +4,13 @@ require 'rails/generators'
4
4
  module Rapidfire
5
5
  module Generators
6
6
  class ViewsGenerator < Rails::Generators::Base
7
- source_root File.expand_path("../../../../app/views/rapidfire", __FILE__)
8
- desc "Copies default Rapidfire views to your application."
7
+ source_root File.expand_path('../../../../app/views/rapidfire', __FILE__)
8
+ desc 'Copies default Rapidfire views to your application.'
9
9
 
10
10
  def copy_views
11
- view_directory :answer_groups
11
+ view_directory :attempts
12
12
  view_directory :answers
13
- view_directory :question_groups
13
+ view_directory :surveys
14
14
  view_directory :questions
15
15
  end
16
16
 
@@ -1,3 +1,3 @@
1
1
  module Rapidfire
2
- VERSION = '2.1.0'
2
+ VERSION = '3.0.0'
3
3
  end
@@ -0,0 +1,10 @@
1
+ namespace :rapidfire do
2
+ namespace :upgrade do
3
+ namespace :migrations do
4
+ desc "Renaming rapidfire_answer_groups to rapidfire_attempts and rapidfire_question_groups to surveys"
5
+ task from210to300: :environment do
6
+ `rails generate rapidfire:upgrade_migration`
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rapidfire::AttemptsController do
4
+ before do
5
+ @routes = Rapidfire::Engine.routes
6
+ end
7
+
8
+ # this scenario is possible when there is only 1 radio button question, and
9
+ # user has not selected any option. in this case, browser doesn't send
10
+ # any default value.
11
+ context 'when no parameters are passed' do
12
+ it 'initializes answer builder with empty args' do
13
+ survey = FactoryGirl.create(:survey)
14
+
15
+ expect {
16
+ post :create, survey_id: survey.id
17
+ }.not_to raise_error
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,261 @@
1
+ == Welcome to Rails
2
+
3
+ Rails is a web-application framework that includes everything needed to create
4
+ database-backed web applications according to the Model-View-Control pattern.
5
+
6
+ This pattern splits the view (also called the presentation) into "dumb"
7
+ templates that are primarily responsible for inserting pre-built data in between
8
+ HTML tags. The model contains the "smart" domain objects (such as Account,
9
+ Product, Person, Post) that holds all the business logic and knows how to
10
+ persist themselves to a database. The controller handles the incoming requests
11
+ (such as Save New Account, Update Product, Show Post) by manipulating the model
12
+ and directing data to the view.
13
+
14
+ In Rails, the model is handled by what's called an object-relational mapping
15
+ layer entitled Active Record. This layer allows you to present the data from
16
+ database rows as objects and embellish these data objects with business logic
17
+ methods. You can read more about Active Record in
18
+ link:files/vendor/rails/activerecord/README.html.
19
+
20
+ The controller and view are handled by the Action Pack, which handles both
21
+ layers by its two parts: Action View and Action Controller. These two layers
22
+ are bundled in a single package due to their heavy interdependence. This is
23
+ unlike the relationship between the Active Record and Action Pack that is much
24
+ more separate. Each of these packages can be used independently outside of
25
+ Rails. You can read more about Action Pack in
26
+ link:files/vendor/rails/actionpack/README.html.
27
+
28
+
29
+ == Getting Started
30
+
31
+ 1. At the command prompt, create a new Rails application:
32
+ <tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
33
+
34
+ 2. Change directory to <tt>myapp</tt> and start the web server:
35
+ <tt>cd myapp; rails server</tt> (run with --help for options)
36
+
37
+ 3. Go to http://localhost:3000/ and you'll see:
38
+ "Welcome aboard: You're riding Ruby on Rails!"
39
+
40
+ 4. Follow the guidelines to start developing your application. You can find
41
+ the following resources handy:
42
+
43
+ * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
44
+ * Ruby on Rails Tutorial Book: http://www.railstutorial.org/
45
+
46
+
47
+ == Debugging Rails
48
+
49
+ Sometimes your application goes wrong. Fortunately there are a lot of tools that
50
+ will help you debug it and get it back on the rails.
51
+
52
+ First area to check is the application log files. Have "tail -f" commands
53
+ running on the server.log and development.log. Rails will automatically display
54
+ debugging and runtime information to these files. Debugging info will also be
55
+ shown in the browser on requests from 127.0.0.1.
56
+
57
+ You can also log your own messages directly into the log file from your code
58
+ using the Ruby logger class from inside your controllers. Example:
59
+
60
+ class WeblogController < ActionController::Base
61
+ def destroy
62
+ @weblog = Weblog.find(params[:id])
63
+ @weblog.destroy
64
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
65
+ end
66
+ end
67
+
68
+ The result will be a message in your log file along the lines of:
69
+
70
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
71
+
72
+ More information on how to use the logger is at http://www.ruby-doc.org/core/
73
+
74
+ Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
75
+ several books available online as well:
76
+
77
+ * Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
78
+ * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
79
+
80
+ These two books will bring you up to speed on the Ruby language and also on
81
+ programming in general.
82
+
83
+
84
+ == Debugger
85
+
86
+ Debugger support is available through the debugger command when you start your
87
+ Mongrel or WEBrick server with --debugger. This means that you can break out of
88
+ execution at any point in the code, investigate and change the model, and then,
89
+ resume execution! You need to install ruby-debug to run the server in debugging
90
+ mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
91
+
92
+ class WeblogController < ActionController::Base
93
+ def index
94
+ @posts = Post.all
95
+ debugger
96
+ end
97
+ end
98
+
99
+ So the controller will accept the action, run the first line, then present you
100
+ with a IRB prompt in the server window. Here you can do things like:
101
+
102
+ >> @posts.inspect
103
+ => "[#<Post:0x14a6be8
104
+ @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
105
+ #<Post:0x14a6620
106
+ @attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
107
+ >> @posts.first.title = "hello from a debugger"
108
+ => "hello from a debugger"
109
+
110
+ ...and even better, you can examine how your runtime objects actually work:
111
+
112
+ >> f = @posts.first
113
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
114
+ >> f.
115
+ Display all 152 possibilities? (y or n)
116
+
117
+ Finally, when you're ready to resume execution, you can enter "cont".
118
+
119
+
120
+ == Console
121
+
122
+ The console is a Ruby shell, which allows you to interact with your
123
+ application's domain model. Here you'll have all parts of the application
124
+ configured, just like it is when the application is running. You can inspect
125
+ domain models, change values, and save to the database. Starting the script
126
+ without arguments will launch it in the development environment.
127
+
128
+ To start the console, run <tt>rails console</tt> from the application
129
+ directory.
130
+
131
+ Options:
132
+
133
+ * Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
134
+ made to the database.
135
+ * Passing an environment name as an argument will load the corresponding
136
+ environment. Example: <tt>rails console production</tt>.
137
+
138
+ To reload your controllers and models after launching the console run
139
+ <tt>reload!</tt>
140
+
141
+ More information about irb can be found at:
142
+ link:http://www.rubycentral.org/pickaxe/irb.html
143
+
144
+
145
+ == dbconsole
146
+
147
+ You can go to the command line of your database directly through <tt>rails
148
+ dbconsole</tt>. You would be connected to the database with the credentials
149
+ defined in database.yml. Starting the script without arguments will connect you
150
+ to the development database. Passing an argument will connect you to a different
151
+ database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
152
+ PostgreSQL and SQLite 3.
153
+
154
+ == Description of Contents
155
+
156
+ The default directory structure of a generated Ruby on Rails application:
157
+
158
+ |-- app
159
+ | |-- assets
160
+ | | |-- images
161
+ | | |-- javascripts
162
+ | | `-- stylesheets
163
+ | |-- controllers
164
+ | |-- helpers
165
+ | |-- mailers
166
+ | |-- models
167
+ | `-- views
168
+ | `-- layouts
169
+ |-- config
170
+ | |-- environments
171
+ | |-- initializers
172
+ | `-- locales
173
+ |-- db
174
+ |-- doc
175
+ |-- lib
176
+ | |-- assets
177
+ | `-- tasks
178
+ |-- log
179
+ |-- public
180
+ |-- script
181
+ |-- test
182
+ | |-- fixtures
183
+ | |-- functional
184
+ | |-- integration
185
+ | |-- performance
186
+ | `-- unit
187
+ |-- tmp
188
+ | `-- cache
189
+ | `-- assets
190
+ `-- vendor
191
+ |-- assets
192
+ | |-- javascripts
193
+ | `-- stylesheets
194
+ `-- plugins
195
+
196
+ app
197
+ Holds all the code that's specific to this particular application.
198
+
199
+ app/assets
200
+ Contains subdirectories for images, stylesheets, and JavaScript files.
201
+
202
+ app/controllers
203
+ Holds controllers that should be named like weblogs_controller.rb for
204
+ automated URL mapping. All controllers should descend from
205
+ ApplicationController which itself descends from ActionController::Base.
206
+
207
+ app/models
208
+ Holds models that should be named like post.rb. Models descend from
209
+ ActiveRecord::Base by default.
210
+
211
+ app/views
212
+ Holds the template files for the view that should be named like
213
+ weblogs/index.html.erb for the WeblogsController#index action. All views use
214
+ eRuby syntax by default.
215
+
216
+ app/views/layouts
217
+ Holds the template files for layouts to be used with views. This models the
218
+ common header/footer method of wrapping views. In your views, define a layout
219
+ using the <tt>layout :default</tt> and create a file named default.html.erb.
220
+ Inside default.html.erb, call <% yield %> to render the view using this
221
+ layout.
222
+
223
+ app/helpers
224
+ Holds view helpers that should be named like weblogs_helper.rb. These are
225
+ generated for you automatically when using generators for controllers.
226
+ Helpers can be used to wrap functionality for your views into methods.
227
+
228
+ config
229
+ Configuration files for the Rails environment, the routing map, the database,
230
+ and other dependencies.
231
+
232
+ db
233
+ Contains the database schema in schema.rb. db/migrate contains all the
234
+ sequence of Migrations for your schema.
235
+
236
+ doc
237
+ This directory is where your application documentation will be stored when
238
+ generated using <tt>rake doc:app</tt>
239
+
240
+ lib
241
+ Application specific libraries. Basically, any kind of custom code that
242
+ doesn't belong under controllers, models, or helpers. This directory is in
243
+ the load path.
244
+
245
+ public
246
+ The directory available for the web server. Also contains the dispatchers and the
247
+ default HTML files. This should be set as the DOCUMENT_ROOT of your web
248
+ server.
249
+
250
+ script
251
+ Helper scripts for automation and generation.
252
+
253
+ test
254
+ Unit and functional tests along with fixtures. When using the rails generate
255
+ command, template test files will be generated for you and placed in this
256
+ directory.
257
+
258
+ vendor
259
+ External libraries that the application depends on. Also includes the plugins
260
+ subdirectory. If the app has frozen rails, those gems also go here, under
261
+ vendor/rails/. This directory is in the load path.