我創建了一個新的Rails項目。畢竟,我有一個問題,我找不到任何地方或自己回答,所以我需要你的幫助。在Rails中創建URL和新建
當您創建新對象(如Person,Book)時,您需要2個操作:NEW
和CREATE
。
當我創造新的,我有鏈接:localhost:3000/admin/books/new
,然後當我創建失敗,將返回ERROR MESSAGE
ANF此鏈接:localhost:3000/admin/books/create
If I click in url and `ENTER`. It will wrong.
我試圖使用redirect_to
或render
如果創作失敗。但沒有任何事情發生,有時會轉到new
頁面,但它不顯示錯誤消息。
我認爲是Rails中的一條規則。 But I still want to ask that anyone have any idea to resolve this problem??? Go to
新link with
錯誤消息if they're failed
更多詳細信息:我正在使用Typus gem爲管理員創建視圖。所以我找不到Routes文件。我跑rake routes
,並得到:
GET /admin/books/(:/action(/:id)) (.:format)
POST /admin/books/(:/action(/:id)) (.:format)
PATCH /admin/books/(:/action(/:id)) (.:format)
DELETE /admin/books/(:/action(/:id)) (.:format)
和控制器時創建的書:
if result
format.html { redirect_on_success }
format.json { render json: @item }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @item.errors, status: :unprocessable_entity }
end
感謝您的幫助:)
你能表現你對這些模型的具體路線?我想你沒有使用RESTful。 – 2016-01-22 03:59:25
告訴我們你的路線和控制器中有什麼 –
我使用TYPUS gem for admin創建新書。所以我找不到路線。 –