新手问题 redirect_to 问题

jiwoorico · 2013年09月09日 · 最后由 ChanceDoor 回复于 2013年09月10日 · 2480 次阅读
def show
    begin
      @cart = Cart.find(params[:id])
    rescue ActiveRecord::RecordNotFound
      logger.error "Attempt to access invalid cart #{params[:id]}"
      redirect_to store_url, notice: 'Invalid cart'
    else
      respond_to do |format|
        format.html # show.html.erb
        format.json { render json: @cart }
      end
    end
  end

这里 redirect_to store_url, notice: 'Invalid cart' 是指 redirect 到哪个 page?store_url 是指什么?谢谢

$ rake routes

#1 楼 @nightire line_items GET /line_items(.:format) line_items#index POST /line_items(.:format) line_items#create w_line_item GET /line_items/new(.:format) line_items#new t_line_item GET /line_items/:id/edit(.:format) line_items#edit line_item GET /line_items/:id(.:format) line_items#show PUT /line_items/:id(.:format) line_items#update DELETE /line_items/:id(.:format) line_items#destroy carts GET /carts(.:format) carts#index POST /carts(.:format) carts#create new_cart GET /carts/new(.:format) carts#new edit_cart GET /carts/:id/edit(.:format) carts#edit cart GET /carts/:id(.:format) carts#show PUT /carts/:id(.:format) carts#update DELETE /carts/:id(.:format) carts#destroy store_index GET /store/index(.:format) store#index products GET /products(.:format) products#index POST /products(.:format) products#create new_product GET /products/new(.:format) products#new dit_product GET /products/:id/edit(.:format) products#edit product GET /products/:id(.:format) products#show PUT /products/:id(.:format) products#update DELETE /products/:id(.:format) products#destroy store / store#index 这里有 store_index 和 store,请问是指哪个?哪里规定 store_url 的指向?谢谢

store, 实际上你的 store 和 store_index 是一样的吧。

建议你去看一下官方指南关于路由的一章。

进入 rails console

app.store_url

#4 楼 @rociiu 我是 windows 的,我运行 app.store_url 说认不出来

#5 楼 @jiwoorico 应该会认出来的 难道报错说 No route matches?你的 store_url 对应的是最下面的 store~

需要 登录 后方可回复, 如果你还没有账号请 注册新账号