我遇到了類似的問題,因爲此前SO question,但答案似乎不適合我。所以我想跟進我的問題。Rails 3控制器更新操作在本地工作,但不在heroku上,失去模板錯誤
我在我的控制器中使用複選框更新我的配置文件模型。當我點擊與本地運行的應用程序的複選框,我沒有任何問題。然而,當我部署到Heroku上我得到:
ActionView::MissingTemplate (Missing template profiles/show_hometown_settings with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:en, :en]} in view paths "/app/app/views", "/app/vendor/plugins/rails_log_stdout/app/views", "/app/vendor/plugins/rails3_serve_static_assets/app/views", "/app/vendor/plugins/paperclip/app/views"):
我添加既是_show_hometown_settings.html.erb
文件和_show_hometown_settings.js.erb
文件,但也沒有獲得成功。檢查我的複選框給我在我的屏幕上的香草代碼和上述錯誤。
如果我添加show_hometown_settings.html.erb
我不再獲得香草代碼。我看到show_hometown_settings.html.erb
模板,但仍然出現錯誤,我沒有被重定向到我的settings_path
,這是整點(檢查更新,發佈到數據庫,重定向進行進一步的設置更改)。任何人都可以幫我解決這個問題嗎?
這裏是控制器動作:
def show_hometown_settings
@profile = current_user.profile
if @profile.show_hometown == true
if @profile.update_attributes(:show_hometown => false)
redirect_to settings_path
else
redirect_to settings_path, :notice => 'Oops, something went wrong. Please try again.'
end
elsif @profile.show_hometown == false
if @profile.update_attributes(:show_hometown => true)
redirect_to settings_path
else
redirect_to settings_path, :notice => 'Oops, something went wrong. Please try again.'
end
end
end
這是我使用的動作形式:
<%= form_tag({:action => "show_hometown_settings", :controller => "profiles"}, :html => {:multipart => true }) do %>
<%= check_box_tag(:show_hometown, 1, @user.profile.show_hometown ? true : false) %>
<%= @user.profile.hometown %>
<% end %>
UPDATE:這裏是我的routes.rb
文件的部分引用的操作:
match "profiles/show_hometown_settings", :to => "profiles#show_hometown_settings"
更新2:低於繼的問題,我有一個不同的錯誤,我的日誌顯示的路線問題:
這將返回
`The page you were looking for doesn't exist (404)`
在我heroku logs --tail
我看到
2012-01-19T23:13:47+00:00 app[web.1]: Started POST "/profiles/show_hometown_settings" for 98.218.231.113 at 2012-01-19 23:13:47 +0000
2012-01-19T23:13:47+00:00 app[web.1]:
2012-01-19T23:13:47+00:00 app[web.1]: ActionController::RoutingError (No route matches "/profiles/show_hometown_settings"):
如果我將路線從:via => [:put]更改爲:via => [:post]它的工作原理。希望沒關係。
你確定你有相關的文件在git中提交? – zsquare 2012-01-18 13:53:34
幾乎肯定。如果我提交'show_hometown_settings',我的想法會變得很糟糕,但我仍然遇到錯誤。 – tvalent2 2012-01-18 15:17:44
您是否嘗試過在重定向後添加'return'?它聽起來像Rails試圖渲染show_hometown_settings動作,即使每個邏輯路徑都會導致重定向。 – MrTheWalrus 2012-01-18 16:46:34