Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9292663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:56:03+00:00 2026-06-18T20:56:03+00:00

In my controller, I have this: class TestController < ApplicationController respond_to :html, :json #

  • 0

In my controller, I have this:

class TestController < ApplicationController
  respond_to :html, :json

  # code...

  def create
    @test = current_user.tests.create(params[:test])
    respond_with @test, location: tests_url
  end

  # code...

end

That’s cool, when I create the test, it redirects to test#index (as expected), but, if I press F5, the browser asks me to resubmit the form.

If I remove the location statement from respond_with it works just fine, but doesn’t go to URL I want.

How could I fix this?

Thanks in advance.


EDIT

I change my method to

@test = current_user.tests.new(params[:transaction])
respond_with(@test) do |format|
  format.html { redirect_to "/tests/" } if @test.save
end

And it works.. but, It’s kinda weird I had to use a String instead of tests_url.


EDIT 2

See this complete example code amd the
Bug report.


EDIT 3

I’m unable to reproduce it with Ruby 1.9.3-p327, only in -p385.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T20:56:05+00:00Added an answer on June 18, 2026 at 8:56 pm

    You could just use the redirect_to method, like this:

    def create
      @test = current_user.tests.create(params[:test])
      respond_with @test do |format|
        format.html { redirect_to tests_path }
      end
    end
    

    Then, if the client asks for a json response, the default to_json behavior will be triggered, but if the response format desired is html, then a redirect will be sent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have controller methods that look like this: class TestController < ApplicationController def testAction
I have this controller: class SchedulesController post, :except => :index def index #Schedules.create(:id =>
I have this controller in Code Igniter that begins with class MyController extends CI_Controller
I have a controller with a action similar to this class EventsController < ApplicationController
I have controller: package plugin class TestController { def simply = {[name:new Date()]} }
I have this controller: public class StandingsController : Controller { public ViewResult Index(int id)
I have a controller that looks like this: public class PageController : Controller {
I have a Controller with syntax like this: public class CrudController<TEntity> : Controller Now
I have a class like this: abstract class CrudResource extends Controller { type ResourceIdType
Say I have a class ObjectA (a view controller for example), that does this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.