我在從Heroku的本地開發到生產方面遇到問題。除了我在'留言簿'控制器中的一個'新'動作外,一切正常。當我嘗試導航到https://allbugsaside.herokuapp.com/guestbooks/new時,出現錯誤提示我要查看日誌。當我運行Heroku日誌時,除了發起請求之外,它並沒有告訴我很多。Heroku路由/控制器從開發到產品時的問題?
我有一種感覺,我可能會得到這個問題,因爲在我的'新'行動中,我打電話給所有目前沒有任何數據的留言板上?只是一個理論。
任何人都可以協助解決這個問題嗎?謝謝。
class GuestbooksController < ApplicationController
def index
@guestbooks = Guestbook.all
end
def new
@guestbook = Guestbook.new
@guestbooks = Guestbook.all
@guestbooks = Kaminari.paginate_array(@guestbooks).page(params[:page]).per(5)
end
def create
@guestbook = Guestbook.new(guestbook_params)
# @guestbooks = Guestbook.all.limit(1).page(params[:page])
if @guestbook.save
flash.now[:notice] = "Thanks for taking the time to write us! We greatly appreciate it!"
render :new
else
flash.now[:notice] = "Your message failed to post, please try again"
render :new
end
end
private
def guestbook_params
params.require(:guestbook).permit(:name, :email, :message)
end
end
這是我new.html.erb
<h1 class="guestbook_head">Guestbook</h1><br/>
<div class="guestbook_text">
<p>
It is our goal to provide our customers with the best possible Pest Control Services and Solutions in the industry.
Your comments and feedback are important to us. They are a tool we use in order to keep on improving our experience, with you ….the customer. <br/><br/>
</p>
</div>
<div class="paginate">
<%= paginate @guestbooks %>
</div>
<div class="span1">
<% @guestbooks.each do |g| %>
<br/>
<h4><%= g.name %>, <%= g.created_at %><br/></h4>
<%= g.message %><br/>
<p>-----------------------------------------------------------------------------------------------------------------------</p>
<% end %>
</div>
<%= simple_form_for @guestbook, url: guestbooks_path, method: :post do |f| %>
<div class="span2"><%= f.input :name %></div>
<div class="span2"><%= f.input :email %></div>
<div class="span3"><%= f.input :message %></div>
<div class="span4"><%= f.button :submit %></div><br/><br/><br/>
<% end %>
這些都是我的路線;
Rails.application.routes.draw do
resources :pages, only: [:index]
get "/pages/home", to: "pages#home"
get "/pages/about", to: "pages#about"
get "/pages/pest_info", to: "pages#pest_info"
get "/pages/annual_contracts", to: "pages#annual_contracts"
get "/pages/monthly_info", to: "pages#monthly_info"
get "/pages/snowplow", to: "pages#snowplow"
get "/pages/gallery", to: "pages#gallery"
resources :contact_form, only: [:new, :create]
resources :guestbooks, only: [:new, :create]
get "/guestbooks/index", to: "guestbooks#index"
root "pages#home"
end
當我嘗試訪問該頁面時,出現500內部服務器錯誤。
2015-12-06T18:42:33.507953+00:00 heroku[router]: at=info method=GET path="/pages/about" host=allbugsaside.herokuapp.com request_id=e07095da-734c-4fe3-aaa8-6f68d86a8e20 fwd="96.248.110.224" dyno=web.1 connect=0ms service=7ms status=200 bytes=5022
2015-12-06T18:42:40.331424+00:00 heroku[router]: at=info method=GET path="/guestbooks/new" host=allbugsaside.herokuapp.com request_id=134c9aab-f559-4e95-bad5-c1037dd38291 fwd="96.248.110.224" dyno=web.1 connect=0ms service=8ms status=500 bytes=1754
2015-12-06T18:42:40.390097+00:00 heroku[router]: at=info method=GET path="/guestbooks/new" host=allbugsaside.herokuapp.com request_id=d552b372-80fa-4e76-83a3-371aa4f994ab fwd="96.248.110.224" dyno=web.1 connect=0ms service=7ms status=500 bytes=1754
當您執行'resources:guestbooks,只有:[:new,:create,:index]'時,索引是可用的,通過Rails約定,您可以通過url:'/ guestbooks'或link_to '代碼在任何視圖:'guestbooks_path'。 –
我明白你的意思了。良好的代碼捕獲。雖然沒有解決問題。 – Jbur43