我是RoR的新手,目前正在完成一些測試任務。 我需要的是從我的形式,命中顯示按鈕的select_tag
選擇update_date
之後,我想看看在同一頁面上(在「更新容器」的index.html格)從相對應根據所選updated_date
分貝信息。我試圖谷歌它以及'stackoverflowed'它,但每次我剛剛陷入更多&更多。從選擇欄選擇選項後更新index.html db值
我index.html.slim:
.container
.child-container
.show-date
= form_tag('/show',
method: :get,
remote: true,
enforce_utf8: false,
:'data-update-target' => 'update-container',
class: 'select_date')
do
= collection_select(:id, :id, Dashboard.all, :id, :update_date)
= submit_tag 'Show', name: nil
#update-container
我的routes.rb:
Rails.application.routes.draw do
resources :dashboards, only: [:index, :show]
root to: 'dashboards#index'
end
我dashboards_controller.rb:
class DashboardsController < ApplicationController
def index
@dashboards = Dashboard.all
end
def show
@dashboard = Dashboard.find(params[:id])
end
end
從這一點i`ve了「 ActionController :: RoutingError(沒有路由匹配[GET]「/ show」):「。
我將非常感謝任何幫助。提前致謝。
的'''resources'''方法只是ganerates的'''/ dashboards'''和'''/儀表板/:在這種情況下id'''路由。你沒有/ show route(如果你檢查rake路由輸出,你可以看到你的可用路由)。 –
@stockholm_syndrome 試着在你的表單標籤改變'show'到'dashboard_path'(不帶引號) – cnnr
@cnnr,感謝對此事發表評論。然而,使用這種解決方案,我仍然收到「沒有路線匹配......」 –