Skip to content

Commit

Permalink
Completed several todo-s
Browse files Browse the repository at this point in the history
  • Loading branch information
html committed Sep 3, 2010
1 parent 8707cec commit ae77413
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 8 deletions.
19 changes: 16 additions & 3 deletions app/controllers/qa_controller.rb
Expand Up @@ -4,10 +4,23 @@ def index
@new = QuestionsAnswersNew.all

if request.post?
@item = QuestionsAnswersNew.new(params[:questions_answers_new])
if @item.save
redirect_to root_url

if params[:questions_answers_new]
@item = QuestionsAnswersNew.new(params[:questions_answers_new])
if @item.save
redirect_to root_url
end
end

if params[:questions_answers_params]
@period = QuestionsAnswersParams.find_or_create_by_name('period')
if @period && @period.update_attributes!(params[:questions_answers_params])
flash[:period_notice] = "Successfully updated period"
redirect_to root_url
end
end
end

@period = QuestionsAnswersParams.find_by_name('period') unless @period
end
end
2 changes: 2 additions & 0 deletions app/models/questions_answers_params.rb
@@ -0,0 +1,2 @@
class QuestionsAnswersParams < ActiveRecord::Base
end
19 changes: 15 additions & 4 deletions app/views/qa/index.erb
@@ -1,7 +1,8 @@
<% if @existing.empty? %>
There are no existing questions/answers
There are no existing questions/answers found
<% else %>
<table>
Existing questions/answers:
<table border="1">
<tr>
<td>Question</td>
<td>Answer</td>
Expand All @@ -16,9 +17,9 @@
<% end %>
<br/>
<% if @new.empty? %>
There are new questions/answers
No new questions/answers found
<% else %>
<table>
<table border="1">
<tr>
<td>Question</td>
<td>Answer</td>
Expand Down Expand Up @@ -46,3 +47,13 @@
</p>
<%= f.submit %>
<% end %>

Change period: <br/>
<% form_for @period || :questions_answers_params, :html => { :method => :post }, :url => root_url do |f| %>
<%= f.error_messages %>
<p>
Period:<br />
<%= f.text_field :value %>
</p>
<%= f.submit %>
<% end %>
Binary file modified db/development.sqlite3
Binary file not shown.
14 changes: 14 additions & 0 deletions db/migrate/003_create_questions_answers_params.rb
@@ -0,0 +1,14 @@
class CreateQuestionsAnswersParams < ActiveRecord::Migration
def self.up
create_table :questions_answers_params do |t|
t.string :name
t.string :value

t.timestamps
end
end

def self.down
drop_table :questions_answers_params
end
end
10 changes: 10 additions & 0 deletions db/migrate/004_add_dummy_questions_answers.rb
@@ -0,0 +1,10 @@
class AddDummyQuestionsAnswers < ActiveRecord::Migration
def self.up
QuestionsAnswersNew.create :question => "1+1 = ???", :answer => "2"
QuestionsAnswersNew.create :question => "Barak Obama plays role of ...", :answer => "devil or devil's son"
QuestionsAnswersNew.create :question => "3+2 = ???", :answer => "5"
end

def self.down
end
end
9 changes: 8 additions & 1 deletion db/schema.rb
Expand Up @@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 2) do
ActiveRecord::Schema.define(:version => 4) do

create_table "questions_answers_existing", :force => true do |t|
t.text "question", :null => false
Expand All @@ -27,4 +27,11 @@
t.datetime "updated_at"
end

create_table "questions_answers_params", :force => true do |t|
t.string "name"
t.string "value"
t.datetime "created_at"
t.datetime "updated_at"
end

end
9 changes: 9 additions & 0 deletions test/fixtures/questions_answers_params.yml
@@ -0,0 +1,9 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

one:
name: MyString
value: MyString

two:
name: MyString
value: MyString
8 changes: 8 additions & 0 deletions test/unit/questions_answers_params_test.rb
@@ -0,0 +1,8 @@
require 'test_helper'

class QuestionsAnswersParamsTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end

0 comments on commit ae77413

Please sign in to comment.