Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

I kind of separated the handling for the quick answers and the edit i…

…n 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
  • Loading branch information...
commit 1c0759b31b238c60acc3f6bb4a681cc1807f033a 1 parent 1786f7c
@PragTob PragTob authored
View
8 app/controllers/answers_controller.rb
@@ -13,5 +13,13 @@ def create
create!(:notice => "Answer Posted!"){ question_url(params[:question_id]) }
end
+ def update
+ # inherited resorces (gem) magic
+ super do |format|
+ format.html { redirect_to question_url(resource.question) }
+ end
+ end
+
end
+
View
10 app/views/answers/_form.html.haml
@@ -1,9 +1,3 @@
-= simple_form_for(@answer, :url => question_answers_path(@question)) do |f|
- = f.error_notification
+= simple_form_for(resource, :url => @form_url) do |f|
+ = render 'form_content', :f => f
- .inputs
- = f.input :description, :as => :text, :label => "Answer",
- :hint => "You can format your input with <a href=\"http://daringfireball.net/projects/markdown/\">Markdown</a>".html_safe
-
- .actions
- = f.button :submit, :value => "Post Answer", :class => "primary btn"
View
9 app/views/answers/_form_content.html.haml
@@ -0,0 +1,9 @@
+= f.error_notification
+
+.inputs
+ = f.input :description, :as => :text, :label => "Answer",
+ :hint => "You can format your input with <a href=\"http://daringfireball.net/projects/markdown/\">Markdown</a>".html_safe
+
+.actions
+ = f.button :submit, :value => "Post Answer", :class => "primary btn"
+
View
3  app/views/answers/_short_answer.html.haml
@@ -0,0 +1,3 @@
+= simple_form_for(@answer, :url => question_answers_path(@question)) do |f|
+ = render 'answers/form_content', :f => f
+
View
3  app/views/questions/show.html.haml
@@ -34,4 +34,5 @@
= render :partial => "answers/list", :collection => resource.answers
- if can? :create, Answer
- = render :partial => "answers/form"
+ = render :partial => "answers/short_answer"
+
View
6 features/answers.feature
@@ -10,3 +10,9 @@ Feature: CRUD actions for answers
And I should be able to see my answer
And my answer should show on my profile page
+ Scenario: Edit an answer
+ Given a question exists
+ And I answer that question
+ When I edit that answer
+ Then I should see the updated answer
+
View
12 features/step_definitions/answer_steps.rb
@@ -28,3 +28,15 @@
ActionMailer::Base.deliveries.should_not be_empty
end
+When /^I edit that answer$/ do
+ visit question_path(@question)
+ page.find('.answer > .links').click_link('Edit')
+ fill_in 'Answer', with: 'Edit: Did you try magic?'
+ click_button 'Post Answer'
+end
+
+Then /^I should see the updated answer$/ do
+ page.should have_content("#{@user.username} says")
+ page.should have_content('Edit: Did you try magic?')
+end
+
Please sign in to comment.
Something went wrong with that request. Please try again.