views:

23

answers:

1

I am rendering a new action but somehow getting the "index" URL. To be more specific, my create action looks like this:

class ListingsController < ApplicationController
    def create
        @listing = Listing.new(params[:listing])
        @listing.user = @current_user

        if @listing.save
          redirect_to @listing
        else
          flash[:error] = "There were errors"
          render :action => "new"
        end
      end
end

When there are errors, I get the "new" action but my URL is the index URL - http://domain.com/listings

Anyone know why this would happen? My routes file is fairly standard:

map.connect 'listings/send_message', :controller => 'listings', :action => 'send_message'
  map.resources :listings
map.root :controller => "listings"
map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'
A: 

when you render you just get the content that will be returned to the browser as the response body. On Rendering your url is not get changed.

Best example of that create a scaffold application.so when you submit the form on the new and error occurs your 'new.html.erb' is displayed but your url shows domain_name/controller_name/create

Hope that helps :)

Salil