Skip to content

Commit 1c0759b

Browse files
committed
I kind of separated the handling for the quick answers and the edit in the form and thereby introduced two levels of partials, dunno how to do it better atm. Suggestions are always welcome. Also got a sip of the magic of inherited_resources - wow. Contains a little nice cucumber feature. Fixes #126
1 parent 1786f7c commit 1c0759b

7 files changed

Lines changed: 42 additions & 9 deletions

File tree

app/controllers/answers_controller.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,13 @@ def create
1313
create!(:notice => "Answer Posted!"){ question_url(params[:question_id]) }
1414
end
1515

16+
def update
17+
# inherited resorces (gem) magic
18+
super do |format|
19+
format.html { redirect_to question_url(resource.question) }
20+
end
21+
end
22+
1623

1724
end
25+

app/views/answers/_form.html.haml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
= simple_form_for(@answer, :url => question_answers_path(@question)) do |f|
2-
= f.error_notification
1+
= simple_form_for(resource, :url => @form_url) do |f|
2+
= render 'form_content', :f => f
33

4-
.inputs
5-
= f.input :description, :as => :text, :label => "Answer",
6-
:hint => "You can format your input with <a href=\"http://daringfireball.net/projects/markdown/\">Markdown</a>".html_safe
7-
8-
.actions
9-
= f.button :submit, :value => "Post Answer", :class => "primary btn"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
= f.error_notification
2+
3+
.inputs
4+
= f.input :description, :as => :text, :label => "Answer",
5+
:hint => "You can format your input with <a href=\"http://daringfireball.net/projects/markdown/\">Markdown</a>".html_safe
6+
7+
.actions
8+
= f.button :submit, :value => "Post Answer", :class => "primary btn"
9+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
= simple_form_for(@answer, :url => question_answers_path(@question)) do |f|
2+
= render 'answers/form_content', :f => f
3+

app/views/questions/show.html.haml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@
3434
= render :partial => "answers/list", :collection => resource.answers
3535

3636
- if can? :create, Answer
37-
= render :partial => "answers/form"
37+
= render :partial => "answers/short_answer"
38+

features/answers.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ Feature: CRUD actions for answers
1010
And I should be able to see my answer
1111
And my answer should show on my profile page
1212

13+
Scenario: Edit an answer
14+
Given a question exists
15+
And I answer that question
16+
When I edit that answer
17+
Then I should see the updated answer
18+

features/step_definitions/answer_steps.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,15 @@
2828
ActionMailer::Base.deliveries.should_not be_empty
2929
end
3030

31+
When /^I edit that answer$/ do
32+
visit question_path(@question)
33+
page.find('.answer > .links').click_link('Edit')
34+
fill_in 'Answer', with: 'Edit: Did you try magic?'
35+
click_button 'Post Answer'
36+
end
37+
38+
Then /^I should see the updated answer$/ do
39+
page.should have_content("#{@user.username} says")
40+
page.should have_content('Edit: Did you try magic?')
41+
end
42+

0 commit comments

Comments
 (0)