Forum: Ruby on Rails problem of respond_with working on nested resources

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
72a6d1c2016a6ec343248690d4a9eb52?d=identicon&s=25 unknown (Guest)
on 2013-05-23 02:27
(Received via mailing list)
hi all:
    when using namespace or nested resources in routes.rb,such as
"namespace :admin { resources :books }, we can use [:admin,@book] way to
generate path. It works fine in form_for , but when I use it with
respond_with in controller, I get problems.
    The problem is when I put following code in controller:

        def create
         @book=Book.find(params[:id])
         @book.save
        respond_with[:admin,@book]
       end

    if there are some problems and the @book is not saved, the function
should render new action, hence we can get error messages, but now it
render index action. and the log file said it got a error 302. if I
replace
'respond_with [ :admin,@book]' with 'respond_with
@book,:location=>admin_book_path(@book)", it works fine.
    should we not use "[:admin,@book]" way with respond_with?

thanks
This topic is locked and can not be replied to.