I always get the error
No route matches {:action=>"index", :blog_id=>nil, :controller=>"comments"} missing required keys: [:blog_id]
when I'm rendering the show action from a different controller:
def create
#blog = Blog.find params[:blog_id]
#comment = #blog.comments.new(comment_params)
respond_to do |format|
if #comment.save
format.html { redirect_to #comment, notice: 'Comment was successfully created.' }
format.json { render :show, status: :created, location: #comment }
else
format.html { render template: 'blogs/show' }
format.json { render json: #comment.errors, status: :unprocessable_entity }
end
end
end
The error happens after validating. The specific line of code responsible for this is format.html { render template: 'blogs/show' }
Any ideas?
Edit
Here's my routes.rb
Rails.application.routes.draw do resources :comments
devise_for :users
resources :blogs do
resources :comments
member do
get '/update/(:status)', to: 'blogs#update_blog_status'
put :rename
end
collection do
put :destroy_multiple
end
root 'blogs#index'
end
As you can see from the error, why is rails matching me with :action => 'index', controller: 'comments' when I clearly want to render blogs/show?
Edit 2
If you're wondering what I'm doing, I wanted to comment on a blog. So the comment form is in blogs/1 and I wanted to test if validation works. When I didn't enter anything in my comment text area, I'm getting the error.
Edit 3 Posting my blogs/show.html.haml
Forgive me but my show.html is in haml format. If you're not familiar with haml, convert it to erb here http://www.haml-converter.com/
blogs/show.html.haml
%p#notice= notice
%h1
%strong= #blog.title
%hr
%p
= #blog.content
%hr
%p
%strong Comments:
= form_for #comment, url: blog_comments_path(blog_id: params[:id]) do |f|
= f.text_area :message
%br
= f.submit "Post Comment"
%br
%p
%strong All Comments:
- #all_comments.each do |comment|
.panel.panel-default
.panel-body
= comment.message
= link_to 'Edit', edit_blog_path(#blog)
|
= link_to 'Back', blogs_path
Try this in the view:
blog_comments_path(#blog)
The POST with the comment is made to the URL: /blogs/:blog_id/comments.
When the validation fails, you trying to build the form's URL using params[:id] which is nil. Using #blog instance should solve the problem.
The problem come as blog resources create 'index' method routes '/blogs', so when you are trying to access 'blogs/show', its try to find 'index' method for that controllers.
Related
I have a partial solution to my previous issue which is correctly displaying the posts#index and posts#show routes, but is choking after creating a post:
ActionController::UrlGenerationError in PostsController#create
No route matches {:action=>"show", :controller=>"posts"} missing required keys: [:id, :month, :year]
Extracted source (around line #32):
30 respond_to do |format|
31 if #post.save
32 format.html { redirect_to post_path, notice: 'Post was successfully created.' }
33 format.json { render :show, status: :created, location: #post }
34 else
35 format.html { render :new }
…and editing a post:
No route matches [PATCH] "/blog/example-post/blog/2015/09/example-post"
Here are all the files in question (working off the same very simple scaffolded blog):
$ rails new blog
[...]
$ cd blog
# (Add friendly_id to Gemfile & install)
$ rails generate friendly_id
$ rails generate scaffold post title content slug:string:uniq
[...]
$ rake db:migrate
routes.rb
Rails.application.routes.draw do
scope 'blog' do
get '', to: 'posts#index', as: 'posts'
post '', to: 'posts#create'
get '/new', to: 'posts#new', as: 'new_post'
get '/:id/edit', to: 'posts#edit', as: 'edit_post'
get '/:year/:month/:id', to: 'posts#show', as: 'post'
patch '/:id', to: 'posts#update'
put '/:id', to: 'posts#update'
delete '/:year/:month/:id', to: 'posts#destroy'
end
end
post.rb
class Post < ActiveRecord::Base
extend FriendlyId
friendly_id :title, use: :slugged
def year
created_at.localtime.strftime("%Y")
end
def month
created_at.localtime.strftime("%m")
end
end
posts_controller.rb
class PostsController < ApplicationController
before_action :set_post, only: [:show, :edit, :update, :destroy]
def index
#posts = Post.all
end
def show
#post = Post.friendly.find(params[:id])
end
def new
#post = Post.new
end
def edit
#post = Post.friendly.find(params[:id])
end
def create
#post = Post.new(post_params)
respond_to do |format|
if #post.save
format.html { redirect_to post_path, notice: 'Post was successfully created.' }
format.json { render :show, status: :created, location: #post }
else
format.html { render :new }
format.json { render json: #post.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if #post.update(post_params)
format.html { redirect_to post_path, notice: 'Post was successfully updated.' }
format.json { render :show, status: :ok, location: #post }
else
format.html { render :edit }
format.json { render json: #post.errors, status: :unprocessable_entity }
end
end
end
def destroy
#post.destroy
respond_to do |format|
format.html { redirect_to posts_url, notice: 'Post was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_post
#post = Post.friendly.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def post_params
params.require(:post).permit(:title, :content, :slug)
end
end
end
posts_helper.rb
module PostsHelper
def post_path(post)
"blog/#{post.year}/#{post.month}/#{post.slug}"
end
end
app/views/posts/index.html.erb
<p id="notice"><%= notice %></p>
<h1>Listing Posts</h1>
<table>
<thead>
<tr>
<th>Title</th>
<th>Content</th>
<th>Slug</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% #posts.each do |post| %>
<tr>
<td><%= post.title %></td>
<td><%= post.content %></td>
<td><%= post.slug %></td>
<td><%= link_to 'Show', post_path(post) %></td>
<td><%= link_to 'Edit', edit_post_path(post) %></td>
<td><%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Post', new_post_path %>
In summary, here's what works:
/blog/index
/blog/2015/09/example-post
Creating a new post (up until the point where it's supposed to redirect to posts#show when you get the UrlGenerationError mentioned above)
That said, the new post is added to the DB so if you go back to /index the new post will be visible
Destroying a post
…What doesn't work:
Editing a post (the edit page with the form will render, but after submitting your changes you'll get the aforementioned error - and the changes never make it to the DB)
Completing the redirect after creating a new post (mentioned earlier).
/blog/2015/index
/blog/2015/09/index
I'm stoked that I've gotten this far - any guidance to resolving these outstanding issues would be really appreciated!
EDIT
With thanks to #brad-werth, post creation has been fixed with the following change:
posts_controller.rb
def create
#post = Post.new(post_params)
respond_to do |format|
if #post.save
format.html { redirect_to post_path(#post.year, #post.month, #post), notice: 'Post was successfully created.' }
I've also tried resolving the post edit problem in the following way:
Changed the edit route to get '/:year/:month/:id/edit', to: 'posts#edit', as: 'edit_post' and added the following override to posts_helper.rb to keep the index page from breaking:
def edit_post_path(post)
"#{post.year}/#{post.month}/#{post.slug}/edit"
end
And now the "edit" link from the index page is going to the correct URL (/blog/2015/09/example-post/edit - it used to go to /blog/example-post/edit) and successfully renders the edit page. But this results in PATCH breaking (indeed, the updates don't make it to the DB):
No route matches [PATCH] "/blog/2015/09/example-post/blog/2015/09/example-post"
I recognize that this duplication problem likely lies with this edit_post_path override, but the following attempts to force the correct PATCH route have no effect:
Update PATCH route to patch '/:year/:month/:id', to: 'posts#update'
Name the updated PATCH route to as: 'patch' and add PATCH path override to posts_helper:
def patch_path(post)
"#{post.year}/#{post.month}/#{post.slug}"
end
Change the override to:
def patch_path(post)
""
end
Un-name & change PATCH route to patch '', to: 'posts#update'
Looking at the posts_controller, it doesn't look like the problem is there since it's not the redirect is not the problem - and I don't see why #post.update(post_params) would be problematic:
def update
respond_to do |format|
if #post.update(post_params)
format.html { redirect_to #post, notice: 'Post was successfully updated.' }
format.json { render :show, status: :ok, location: #post }
else
format.html { render :edit }
format.json { render json: #post.errors, status: :unprocessable_entity }
end
end
end
So as far as I can tell the duplication in the URL is happening prior to the PATCH action, which brings us back to the EDIT flow - it must be passing the duplication to PATCH where it winds up choking. Ideas?
Your error states:
No route matches {:action=>"show", :controller=>"posts"} missing required keys: [:id, :month, :year]
As you can see from your failing line, format.html { redirect_to post_path, notice: 'Post was successfully created.' }, you are calling post_path with no arguments.
Your route get '/:year/:month/:id', to: 'posts#show', as: 'post' expects a year, month, and id. This jives with your error message above.
To fix, simply supply the missing parameters, like so:
format.html { redirect_to post_path(#post.year, #post.month, #post), notice: 'Post was successfully created.' }
in update and create actions change:
format.html { redirect_to post_path, notice: 'Post was successfully ...' }
with
format.html { redirect_to #post, notice: 'Post was successfully ...' }
I am trying to make an app in Rails 4 using simple form.
I have 3 models: Project, Project_Question, Project_Answer
The associations are:
Project:
has_many :project_questions, dependent: :destroy#, through: :projects
accepts_nested_attributes_for :project_questions
Project Question:
belongs_to :project#, counter_cache: true
has_one :project_answer, dependent: :destroy
belongs_to :user
accepts_nested_attributes_for :project_answer
Project Answer:
belongs_to :project_question#, counter_cache: true
belongs_to :user
My routes are nested as follows:
resources :projects do
resources :project_questions do
resources :project_answers
end
end
In my Project Questions partial, I want a link to answer the question. I have a link that is set out as follows:
<%= link_to 'Answer this question', new_project_project_question_project_answer_path(:project_id => #project.id, :project_question_id => singleQuestion.id) %>
I got help getting to the link point with help on the attached question:
http://stackoverflow.com/questions/30978447/rails-link-to-path
I since changed the project answer model so that project question has one (rather than has many project answers) and updated the path in the Answer this Question link, to singular instead of plural.
When I click the 'Answer this question' link, I get this error:
undefined method `project_answers_path'
It is pointing to the simple form for line in the project answers form. That form has:
<%= simple_form_for [#project, #project_question, #project_answer] do |f| %>
<%= f.input :project_question_id, as: :hidden, input_html: {value: #project_question.id} %>
<%= f.input :answer, label: 'Answer?', :label_html => {:class => 'question-project'}, placeholder: 'Type your answer here', :input_html => {:style => 'width: 650px', class: 'response-project'} %>
<br><br><br>
<%= f.button :submit, 'Send!', :class => "cpb" %>
<% end %>
When I rake routes for project answer, I get:
project_project_question_project_answers GET /projects/:project_id/project_questions/:project_question_id/project_answers(.:format) project_answers#index
POST /projects/:project_id/project_questions/:project_question_id/project_answers(.:format) project_answers#create
new_project_project_question_project_answer GET /projects/:project_id/project_questions/:project_question_id/project_answers/new(.:format) project_answers#new
edit_project_project_question_project_answer GET /projects/:project_id/project_questions/:project_question_id/project_answers/:id/edit(.:format) project_answers#edit
project_project_question_project_answer GET /projects/:project_id/project_questions/:project_question_id/project_answers/:id(.:format) project_answers#show
PATCH /projects/:project_id/project_questions/:project_question_id/project_answers/:id(.:format) project_answers#update
PUT /projects/:project_id/project_questions/:project_question_id/project_answers/:id(.:format) project_answers#update
DELETE /projects/:project_id/project_questions/:project_question_id/project_answers/:id(.:format) project_answers#destroy
I don't understand why the #new action for the project_project_questions_project_answers action is plural for answers when there will only be one answer, but I think this has something to do with the error message I get when I click the 'Answer this Question' link.
new_project_project_question_project_answer GET /projects/:project_id/project_questions/:project_question_id/project_answers/new(.:format) project_answers#new
e
When I try pluralising the first line of the form for project answers, for project questions, like this:
<%= simple_form_for [#project, #project_questions, #project_answer] do |f| %>
I get this error:
undefined method `project_answers_path' for #<#<Class:0x0000010a193f10>:0x0000010a3abb40>
When I try pluralising the first line of the form for project answers, for project questions and project answers, like this:
<%= simple_form_for [#project, #project_questions, #project_answers] do |f| %>
I get this error:
undefined method `model_name' for NilClass:Class
Can anyone see what I've done wrong? I read a post suggesting that I use project_answer (singular) in the routes.rb. I tried this but I get an error saying no route matches the plural.
Project Answer Controller:
class ProjectAnswersController < ApplicationController
before_action :set_project_answer, only: [:show, :edit, :update, :destroy]
# GET /project_answers
# GET /project_answers.json
def index
#project_answers = ProjectAnswer.all
end
# GET /project_answers/1
# GET /project_answers/1.json
def show
end
# GET /project_answers/new
def new
#project_answer = ProjectAnswer.new
end
# GET /project_answers/1/edit
def edit
end
# POST /project_answers
# POST /project_answers.json
def create
#project_answer = ProjectAnswer.new(project_answer_params)
respond_to do |format|
if #project_answer.save
format.html { redirect_to #project_answer, notice: 'Project answer was successfully created.' }
format.json { render action: 'show', status: :created, location: #project_answer }
else
format.html { render action: 'new' }
format.json { render json: #project_answer.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /project_answers/1
# PATCH/PUT /project_answers/1.json
def update
respond_to do |format|
if #project_answer.update(project_answer_params)
format.html { redirect_to #project_answer, notice: 'Project answer was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: #project_answer.errors, status: :unprocessable_entity }
end
end
end
# DELETE /project_answers/1
# DELETE /project_answers/1.json
def destroy
#project_answer.destroy
respond_to do |format|
format.html { redirect_to project_answers_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_project_answer
#project_answer = ProjectAnswer.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def project_answer_params
params[:project_answer].permit(:answer, :project_question_id)
end
end
Your new action of project_answers controller should be having #project, #project_question defined
def new
#project_answer = ProjectAnswer.new
#project = Project.find(params[:project_id])
#project_question = ProjectQuestion.find(params[:project_question_id])
end
So that you can use those in the form like this
<%= simple_form_for [#project, #project_question, #project_answer] do |f| %>
Rails 4.1, reaching the driver knowing edit and use _form.html.erb again. I tried to do the following:
<% = Form_for #user, :controller => "admin/users" do | f |%>
<button type='submit'>Guardar</button>
<% end %>
#Controller
===============
def new
#user = User.new
end
def create
#user = User.new(user_params)
respond_to do |format|
if #user.save
format.html { redirect_to admin_users_url, notice: "User ##user.name} was successfully created." }
format.json { render :controller => 'admin/users', action: 'show', status: :created, location: #user }
else
format.html { render :controller => 'admin/users', action: 'new' }
format.json { render json: #user.errors, status: :unprocessable_entity }
end
end
end
But it does not work I can not get to the route that is my controller ("admin / users"), if anyone can help me
I assume that you have your admin routes defined in your config/routes.rb like this:
# in config/routes.rb
namespace :admin do
resources :users
end
See: Rails Guide about namespaces in routes
Then this should work for an admin namespaced form in your view:
<%= form_for [:admin, #user] do |f| %>
...
<% end %>
See: Rails Guide about namespaces and form helper
Your controller code looks okay, but please ensure that the controller is namespaced too:
# in app/controllers/admin/users_controller.rb
module Admin
class UsersController
# ...
end
end
I am using a ruby on rails blog tutorial and everytime I try to edit a comment I get an error.
Error: No route matches missing required keys: [:id].
Please help I am new to this.
Error found around line 3.
<h1>Editing comment</h1>
3. <%= form_for([:post, #comment]) do |f| %>
4. <div class="field">
5. <%= f.label :name %>
<%= f.text_field :name %>
Here is my routes.rb file code
Rails.application.routes.draw do
resources :posts do
resources :comments
end
end
My Comments_controller.rb code
class CommentsController < ApplicationController
# GET /comments
# GET /comments.json
def index
#comments = Comment.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: #comments }
end
end
# GET /comments/1
# GET /comments/1.json
def show
#comment = Comment.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: #comment }
end
end
# GET /comments/new
# GET /comments/new.json
def new
#comment = Comment.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: #comment }
end
end
# GET /comments/1/edit
def edit
#comment = Comment.find(params[:id])
end
# POST /comments
# POST /comments.json
def create
#post = Post.find(params[:post_id])
#comment = #post.comments.build(comment_params)
respond_to do |format|
if #comment.save
format.html { redirect_to #post, notice: 'Comment was successfully created.' }
format.json { render json: #post, status: :created, location: #comment }
else
format.html { render action: "new" }
format.json { render json: #post.errors, status: :unprocessable_entity }
end
end
end
# PUT /comments/1
# PUT /comments/1.json
def update
#comment = Comment.find(params[:id])
#post = #comment.post
respond_to do |format|
if #comment.update_attributes(params[:comment])
format.html { redirect_to #post, notice: 'Comment was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: #post.errors, status: :unprocessable_entity }
end
end
end
# DELETE /comments/1
# DELETE /comments/1.json
def destroy
#comment = Comment.find(params[:id])
#post = Post.find(params[:post_id])
#comment.destroy
respond_to do |format|
format.html { redirect_to #post, notice: 'Comment was successfully deleted!' }
format.json { head :no_content }
end
end
def comment_params
params.require(:comment).permit(:post_id, :name, :email, :body)
end
end
So, to leave the comments alone, let me try to explain what I think it is your problem.
In your routes file you have nested resources, which means that this:
resources :posts do
resources :comments
end
end
are what is called nested resources, and this means that you have routes like:
posts/:post_id
posts/:post_id/comments/:comment_id
which you can see if you run rake routes.
This also means that the first route will call an action on your PostsController and the second route will call an action on your CommentsController.
So what I suggested you to do in your controller was to, first, render the form as [#post, #comment], which will tell the form_for helper to use your nested resource as the 'path to send the form'.
For this form to call your edit method you'll need to say that you want the form to be submitted there. This is done by the options for the form_for helper (http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html) and this is necessary because rails loves/is! RESTfull, and under this, the same route might have multiple behaviours depending on the HTTP verb/method you use.
So, have attention to this that I mentioned above, and you can probably guess what you are doing wrong.
As a last hint, your controller has this:
# GET /comments/1/edit
def edit
#comment = Comment.find(params[:id])
end
And this method renders this(I assume):
<h1>Editing comment</h1>
<%# I already fixed the form_for here %>
<%= form_for([#post, #comment]) do |f| %>
<div class="field">
<%= f.label :name %>
<%= f.text_field :name %>
<% end %>
This form, since is rendered by the edit action, will (probably) be submitted to the update action. This update action is under /posts/:post_id/comments/:comment_id, and can be called using the PATCH(rails 4.0) verb. So your form_for needs, first, to have a post assigned to the variable #post, which should be passed by its controller. Second, it needs to go to the right route.
Here you are lucky since Rails is smart enough to see if what you're submitting is a new_record? and then its form_for will point to create or, if not, will point to update.
So all you need to do now, is to assign the right Post to #post and you are probably good to go.
Let me know if this worked for you.
I'm new to Rails and making application where college members (teachers and students) can create posts and comment on them. Later on I wish to add nesting (ancestry) and points system in it.
I have Post, Comment and Member model. The Post model was made via Scaffolding, Member model was made with help of Devise, and Comment is just a model.
In my show page of Post, I'd like to have comments beneath the posts, I've made some progress (thanks to SO I came to know quite a bit) but now I am stuck with a problem that whenever I attempt to post a blank comment, rails was redirecting to the edit page. How to change this so that rails stays only on the show page and display errors?
For this I searched a bit, created a new method 'update_comments' in post_controller.rb and tried modifying the forms_for tag attributes, as in the code below, but now I get routing error on submitting.
app/models/member.rb
class Member < ActiveRecord::Base
#Associations
belongs_to :department
has_one :student, :dependent => :destroy
accepts_nested_attributes_for :student
has_one :nstudent, :dependent => :destroy
accepts_nested_attributes_for :nstudent
has_many :posts, :dependent => :destroy
has_many :comments, :dependent => :destroy
end
app/models/post.rb
class Post < ActiveRecord::Base
#Associations
belongs_to :member
has_many :comments, :dependent => :destroy
accepts_nested_attributes_for :comments
end
app/models/comment.rb
class Comment < ActiveRecord::Base
# Associations
belongs_to :member
belongs_to :post
validates_presence_of :content
end
config/routes.rb
Urdxxx::Application.routes.draw do
devise_for :members
resources :posts do
member do
get 'update_comment'
end
end
root :to => 'posts#index'
app/controllers/posts_controller.rb
class PostsController < ApplicationController
# Devise filter that checks for an authenticated member
before_filter :authenticate_member!
# GET /posts
# GET /posts.json
def index
#posts = Post.find(:all, :order => 'points DESC')
respond_to do |format|
format.html # index.html.erb
format.json { render json: #posts }
end
end
...
# GET /posts/1/edit
def edit
#post = Post.find(params[:id])
end
# POST /posts
# POST /posts.json
def create
#post = Post.new(params[:post])
#post.member_id = current_member.id if #post.member_id.nil?
respond_to do |format|
if #post.save
format.html { redirect_to #post, notice: 'Post was successfully created.' }
format.json { render json: #post, status: :created, location: #post }
else
format.html { render action: "new" }
format.json { render json: #post.errors, status: :unprocessable_entity }
end
end
end
# PUT /posts/1
# PUT /posts/1.json
def update
#post = Post.find(params[:id])
respond_to do |format|
if #post.update_attributes(params[:post])
format.html { redirect_to #post, notice: 'Post was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: #post.errors, status: :unprocessable_entity }
end
end
end
# DELETE /posts/1
# DELETE /posts/1.json
def destroy
#post = Post.find(params[:id])
#post.destroy
respond_to do |format|
format.html { redirect_to posts_url }
format.json { head :no_content }
end
end
# Not made by scaffold
def update_comment
#post = Post.find(params[:id])
respond_to do |format|
if #post.update_attributes(params[:post])
format.html { redirect_to #post, notice: 'Comment was successfully created.' }
format.json { head :no_content }
else
format.html { render action: "show" }
format.json { render json: #post.errors, status: :unprocessable_entity }
end
end
end
end
app/views/posts/show.html.erb
<p> Have your say </p>
<%= form_for #post, :url => {:action => 'update_comment'} do |p| %>
<%= p.fields_for :comments do |c| %>
<!-- Following 3 lines saved my life -->
<% if c.object.new_record? %>
<%= c.text_area :content, :rows => 4 %>
<%= c.hidden_field :member_id, value: current_member.id %>
<% end %>
<% end %>
<%= p.submit "Reply" %>
<% end %>
image of my show page:
http://i.stack.imgur.com/TBgKy.png
on making a comment:
http://i.stack.imgur.com/JlWeR.png
Update:
Looked back and made changes here, following what Ken said. I don't know how but it works for now.
app/controllers/posts_controller.rb
def update
#post = Post.find(params[:id])
respond_to do |format|
if #post.update_attributes(params[:post])
format.html { redirect_to #post, notice: 'Post was successfully updated.' }
format.json { head :no_content }
elsif :comments
format.html { render action: "show" }
format.json { render json: #post.errors, status: :unprocessable_entity }
else
format.html { render action: "edit" }
format.json { render json: #post.errors, status: :unprocessable_entity }
end
end
end
You don't need a custom method. It is not very RESTful. See, e.g., http://www.sitepoint.com/restful-rails-part-i/ for info on REST. This is not a case where there is justification to use a custom method.
Whenever you find yourself adding custom methods you should think long and hard about whether it's necessary. Usually if you need custom methods what you actually need is another controller (or a different set of controllers).
The update method here is all you need. If you really want to go to the show method after a failed update (though I don't know why) then change the render edit call in the block in the update method after the update fails.
It seems like your real problem is the edit view isn't showing errors. Although the scaffold generated view should do that so maybe you changed it.
In case you missed it you may also benefit from this screencast:
http://railscasts.com/episodes/196-nested-model-form-part-1
You need to update the method type in route and also needs to sets the form post method to your new action, also when you submit a form its an post request not a get request.
Urdxxx::Application.routes.draw do
devise_for :members
resources :posts do
collection do
post :update_comment
end
end
root :to => 'posts#index'
<p> Have your say </p>
<%= form_for :post, :url => {:action => 'update_comment'} do |p| %>
<%= p.fields_for :comments do |c| %>
<!-- Following 3 lines saved my life -->
<% if c.object.new_record? %>
<%= c.text_area :content, :rows => 4 %>
<%= c.hidden_field :member_id, value: current_member.id %>
<% end %>
<% end %>
<%= p.submit "Reply" %>
<% end %>