RailsCasts Pro episodes are now free!

Learn more or hide this

Brian E. McElaney's Profile

GitHub User: mcelaney

Comments by Brian E. McElaney

Avatar

Nevermind - just realized my issue had to do with something else. I'd delete my comment above but I don't have the ability

Avatar

Tried to follow this tutorial off a scaffold using rspec

ruby
# GET /articles/1
# GET /articles/1.json
def show
  @article = Article.find(params[:id])
  if request.path != article_path(@article)
    redirect_to @article, status: :moved_permanently
  end

  respond_to do |format|
    format.html # show.html.erb
    format.json { render json: @article }
  end
end

Threw the following failure:

ruby
1) ArticlesController GET show assigns the requested article as @article
   Failure/Error: get :show, {:id => article.to_param}, valid_session
   AbstractController::DoubleRenderError:
     Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return".
   # ./app/controllers/articles_controller.rb:21:in `show'
   # ./spec/controllers/articles_controller_spec.rb:55:in `block (3 levels) in <top (required)>'

Quick fix I'm using... but if there is a more eloquent way I'd love to know...

ruby
# GET /articles/1
# GET /articles/1.json
def show
  @article = Article.find(params[:id])
  if request.path != article_path(@article)
    redirect_to @article, status: :moved_permanently
  else
    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @article }
    end
  end
end