[英]Really simple routing error, what am I missing?
我覺得這是一個非常簡單的錯誤,我只是沒有看到...
請求控制器
def create
if @request.save
redirect_to 'success'
else
render 'new'
end
end
def success
end
查看, requests/success.html.erb
<h1> Testing, this is the Success page that should be rendered </h1>
路線
get 'requests/new', to: 'requests#new', as: 'new_request'
post 'requests', to: 'requests#create'
get 'requests/success', to: 'requests#success'
但是,現在,當我完成成功的創建時,我不會呈現成功頁面。 相反,它似乎正試圖把我帶到一個奇怪的地方。 這是日志輸出:
Redirected to http://localhost:3000success
Completed 302 Found in 10ms (ActiveRecord: 2.2ms)
[2014-06-25 10:49:24] ERROR URI::InvalidURIError: the scheme http does not accept registry part: localhost:3000success (or bad hostname?)
注意,如果在控制器中將成功的重定向更改為redirect_to root_path
它將起作用。
將路線更改為
get 'requests/success', to: 'request#success', as: 'success'
然后在您的控制器內,您可以擁有
def create
if @request.save
redirect_to success_path
else
render 'new'
end
end
同樣在您的路線中,您有'requests#success'
, 'requests#create'
您應該將它們更改為'request#success'
和'request#create'
以獲得更多信息,請參見此處
將您的控制器更改為此;
def create
if @request.save
redirect_to action: 'success'
else
render action: 'new'
end
end
def success
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.