如何设置路径?
运行rails应用程序时出现以下错误:
No route matches {:action=>"search", :controller=>"inbox"} missing required keys: [:id]
我认为这与我的routes.rb文件有关。 我正在搜索栏上工作,每次搜索时,它都会循环回到主页,因为我没有路径集。
这是我的index.erb.html文件。
<%= form_tag inbox_search_path, :method => 'get' do %>
<p>
<%= search_field_tag :Search, params[:search] %>
<%= submit_tag "Search", :name => nil %>
</p>
<% end %>
这是我的routes.rb文件。
Rails.application.routes.draw do
resources :webinars
resources :topic_proposals
resources :webinar_questions
get 'webinars/show/' => 'webinars#show', :as => 'webinars_show'
get 'webinars/edit/:id' => 'webinars#edit', :as => 'webinars_edit'
get 'webinars/delete_webinar/:id' => 'webinars#delete_webinar', :as => 'webinars_delete_webinar'
resources :categories_skills
resources :categories
get 'home/download_pdf'
get 'static/:view' => 'static#show', :as => 'static'
get 'lists/:id/members' => 'lists#members', :as => 'list_members'
post 'lists/:id/update_mailchimp_list' => 'lists#update_mailchimp', :as => 'update_mailchimp_list'
# put 'lists/:id/' => 'lists#update', :as => 'list_update'
# get 'lists' => 'lists#index', :as => 'lists'
resources :lists
resources :emails
post 'emails/upload' => 'emails#upload', :as => 'upload_emails'
resources :campaigns
resources :affiliates
resources :answers
resources :questions
resources :messages
resources :schools
resources :payments
resources :assessments do
resources :questions do
resources :responses
end
end
get 'tryout' => "tryout#index"
get 'take/assessments' => 'take_assessment#show', :as => 'take_assessments'
get 'take/assessments/start' => 'take_assessment#start', :as => 'start_assessments'
get 'take/assessments/summary' => 'take_assessment#summary', :as => 'summary_assessment'
get 'take/assessments/select_school_year' => 'take_assessment#select_school_year', :as => 'select_school_year'
get 'quiz-results' => 'quiz_results#summary', :as => 'quiz-results'
match 'connect/mentors' => 'connect_mentors#index', :as => 'connect_mentors', via: [:get, :post]
get 'connect/mentors/:id' => 'connect_mentors#show', :as => 'show_mentor'
get 'connect/students/:id' => 'connect_students#show', :as => 'show_student'
devise_scope :user do
get 'partners/:invitation_code' => 'partners#landing', as: 'partners_landing'
get 'partners/:code/new' => 'partners#new', as: 'partners_new'
post 'partners' => 'partners#create', as: 'partners_registration'
end
devise_scope :user do
get 'members/new' => 'members#new', as: 'members_new'
get 'members/new/:variation' => 'members#new', as: 'members_new_variation'
post 'members' => 'members#create', as: 'members_registration'
end
resource :user, only: [:edit] do
collection do
patch 'update_password'
patch 'update_notification_email'
patch 'update_school_year_id', :controller=>"take_assessment"
end
end
get 'learn' => "lesson_plans#index"
get 'lesson-plans/:id' => 'lesson_plans#show', as: 'lesson_plan'
get 'content/:id' => 'content#show', as: :content
get 'content/:id/review' => 'content#review', as: 'content_review'
get 'mentors/:id/conversation' => 'conversations#index', as: 'mentor_conversation'
get 'mentors/:id/conversations/new' => 'conversations#new', as: 'new_mentor_conversation'
get 'profile' => 'profile#show', as: 'user_profile'
get 'redeem' => 'redeem_invitations#validate_redeem_code', as: 'redeem_code'
resources :request_invitations
resources :payment_types
resources :articles
resources :skills
resources :portals
resources :school_sessions
resources :school_years
resources :conversations do
resource :messages, only: [:new, :create]
end
resources :grade_levels
resources :messages, only: [:index, :show]
resources :lookup do
get :lookup_mentor_name, :on => :collection
get :lookup_student_name, :on => :collection
end
get 'inbox' => 'inbox#index', :as => 'inbox_index'
get 'inbox/show/:id' => 'inbox#show', :as => 'inbox_show'
get 'inbox/compose' => 'inbox#compose', :as => 'inbox_compose'
get 'inbox/compose/:id' => 'inbox#compose', :as => 'inbox_compose_to'
get 'inbox/edit/:id' => 'inbox#edit', :as => 'inbox_edit'
get 'inbox/move' => 'inbox#move', :as => 'inbox_move'
get 'inbox/reply' => 'inbox#reply', :as => 'inbox_reply'
post 'inbox/create' => 'inbox#create'
post 'inbox/bulk' => 'inbox#bulk'
post 'memberships/agree' => 'memberships#agree'
get 'memberships/new' => 'memberships#new', :as => 'memberships_new'
get 'memberships/terms' => 'memberships#terms', :as => 'memberships_terms'
get 'memberships/success/:id' => 'memberships#success', :as => 'memberships_success'
get 'memberships/failure' => 'memberships#failure', :as => 'memberships_failure'
get 'memberships/paypal_payment' => 'memberships#paypal_payment', :as => 'paypal_payment'
get 'memberships/paypal_payment_step_2' => 'memberships#paypal_payment_step_2', :as => 'paypal_payment_step_2'
resources :memberships
post 'memberships/hook' => 'memberships#hook'
get 'admin/dashboard/export_cert' => 'admin_dashboard#export_certs', :as => 'admin_dashboard_export_cert'
get 'admin/dashboard/registrations' => 'admin_dashboard#registrations', :as => 'admin_dashboard_registrations'
get 'admin/dashboard/payments' => 'admin_dashboard#payments', :as => 'admin_dashboard_payments'
get 'admin/dashboard/schoolreports' => 'admin_dashboard#schoolreports', :as => 'admin_dashboard_schoolreports'
get 'admin/dashboard/memberreports' => 'admin_dashboard#memberreports', :as => 'admin_dashboard_memberreports'
get 'admin/dashboard/messagingreports' => 'admin_dashboard#messagingreports', :as => 'admin_dashboard_messagingreports'
get 'admin/dashboard/messaging_mentor_reports' => 'admin_dashboard#messaging_mentor_reports', :as => 'admin_dashboard_messaging_mentor_reports'
get 'admin/dashboard/load_points' => 'admin_dashboard#load_points', :as => 'admin_dashboard_load_points'
get 'admin/dashboard/reset_points' => 'admin_dashboard#reset_points', :as => 'admin_dashboard_reset_points'
get 'admin/dashboard/activate_membership' => 'admin_dashboard#activate_membership', :as => 'admin_dashboard_activate_membership'
get 'admin/dashboard/delete_account' => 'admin_dashboard#delete_account', :as => 'admin_dashboard_delete_account'
get 'admin/dashboard/reset_password/:id' => 'admin_dashboard#reset_password', :as => 'admin_dashboard_reset_password'
get 'admin/members/edit/:id' => 'admin_dashboard#edit', :as => 'edituser'
get 'admin/dashboard/unpaid_members' => 'admin_dashboard#unpaid_members', :as => 'unpaid_members'
patch 'admin/members/edit/:id' => 'admin_dashboard#update' # new code
get 'admin/dashboard/expired_messages' => 'admin_dashboard#expired_messages', :as => 'admin_dashboard_expired_messages'
get 'admin/dashboard/' => 'admin_dashboard#search', :as => 'admin_dashboard'
get 'admin/demo_list/' => 'admin_dashboard#demo_list', :as => 'demo_list'
get 'admin/cleandata/:id' => 'admin_dashboard#data_cleanup', :as => 'data_cleanup'
post 'admin/dashboard/upload' => 'admin_dashboard#upload', :as => 'upload_admin_dashboard'
get 'admin/mentors' => 'mentors#index', :as => 'admin_mentors'
post 'admin/mentors' => 'mentors#create'
get 'admin/mentors/new' => 'mentors#new', :as => 'admin_new_mentor'
get 'admin/mentors/:id' => 'mentors#show', :as => 'admin_mentor'
get 'admin/impersonate'=> 'admin_dashboard#impersonate', :as => 'admin_impersonate'
get 'admin/stop_impersonating'=> 'admin_dashboard#stop_impersonating', :as => 'admin_stop_impersonating'
get 'messages/reply/:id' => 'messages#reply', as: 'reply_to'
get 'credits/new', as: 'new_credits'
get 'dashboard' => 'dashboard#index', as: 'user_root'
get 'seen_message' => 'dashboard#seen_message', as: 'seen_message'
devise_for :users, :controllers => {registrations: 'registrations', passwords: 'passwords'}
# The static site pages
get 'about' => "pages#about", :as => 'about'
get 'joinus' => "pages#membership", :as => 'joinus'
get 'faq' => "pages#faq", :as => "faq"
get 'certification' => "pages#certification", :as => "certification"
get 'chapters' => "pages#chapters", :as => "chapters"
get 'internships' => 'pages#internships', :as => 'internships'
get 'privacy-policy' => 'pages#privacy_policy', :as => 'privacy_policy'
get 'contact-us' => 'pages#contact_us', :as => 'contact_us'
post 'send_message' => "pages#send_message", :as => 'send_contact_us'
get 'terms-of-use' => 'pages#terms', :as => 'terms'
#temporary
get 'pages/accountinfo' => 'pages#accountinfo', :as => "pages_accountinfo"
get 'pages/registration' => 'pages#registration', :as => "pages_registration"
get 'pages/payment' => 'pages#payment', :as => "pages_payment"
# leadership pages
get 'leadership' => 'leadership#index'
get 'leadership/recruitment' => 'leadership#recruitment', :as => "leadership_recruitment"
get 'leadership/advisory' => 'leadership#advisory', :as => "leadership_advisory"
get 'leadership/fredsiegel' => 'leadership#fredsiegel', :as => :fredsiegel
get 'leadership/matttrainum' => 'leadership#matttrainum', :as => :matttrainum
get 'leadership/lenormanstrong' => 'leadership#lenormanstrong', :as => :lenormanstrong
get 'leadership/arlenecash' => 'leadership#arlenecash', :as => :arlenecash
get 'leadership/ernestolopez' => 'leadership#ernestolopez', :as => :ernestolopez
get 'leadership/rodneyjohnson' => 'leadership#rodneyjohnson', :as => :rodneyjohnson
get 'leadership/carolaweil' => 'leadership#carolaweil', :as => :carolaweil
get 'leadership/dianenafranowicz' => 'leadership#dianenafranowicz', :as => :dianenafranowicz
get 'leadership/alexakim' => 'leadership#alexakim', :as => :alexakim
get 'leadership/robertkirkwood' => 'leadership#robertkirkwood', :as => :robertkirkwood
get 'leadership/jodyhubbard' => 'leadership#jodyhubbard', :as => :jodyhubbard
get 'leadership/bobbydishell' => 'leadership#bobbydishell', :as => :bobbydishell
get 'leadership/paulhimmelfarb' => 'leadership#paulhimmelfarb', :as => :paulhimmelfarb
get 'leadership/nedjohnson' => 'leadership#nedjohnson', :as => :nedjohnson
get 'leadership/patsidhu' => 'leadership#patsidhu', :as => :patsidhu
get 'leadership/product' => 'pages#product', :as => :product
# internship pages
resources :internship_application
get 'internship' => 'internship_application#index', :as => 'internship'
# Payments Search
get 'internship' => 'payments#search', :as => :paymentssearch
# feature pages
get 'feature/mentor' => 'feature#mentor', :as => "feature_mentor"
get 'feature/advisor' => 'feature#advisor', :as => "feature_advisor"
get 'memberships/accountinfo' => 'memberships#accountinfo', :as => "membership_accountinfo"
resources :contacts, only:[:new, :create]
root 'home#index'
# We need this line to catch any routing error
match '*path(.:format)', :to => 'application#not_found', via: :all
end
这是我在route.rb文件中的相关部分。
get 'inbox' => 'inbox#index', :as => 'inbox_index'
get 'inbox/show/:id' => 'inbox#show', :as => 'inbox_show'
get 'inbox/compose' => 'inbox#compose', :as => 'inbox_compose'
get 'inbox/compose/:id' => 'inbox#compose', :as => 'inbox_compose_to'
get 'inbox/edit/:id' => 'inbox#edit', :as => 'inbox_edit'
get 'inbox/move' => 'inbox#move', :as => 'inbox_move'
get 'inbox/reply' => 'inbox#reply', :as => 'inbox_reply'
post 'inbox/create' => 'inbox#create'
post 'inbox/bulk' => 'inbox#bulk'
get 'inbox/search' => 'inbox#seaarch', :as => 'inbox_search'
答案 0 :(得分:1)
将此路线添加到routes.rb
get 'inbox/search' => 'inbox#search', :as => inbox_search
答案 1 :(得分:1)
看起来您的路线有拼写错误,可能导致其失败。
get 'inbox/search' => 'inbox#seaarch', :as => 'inbox_search'
^
答案 2 :(得分:0)
将您的form_tag
更改为此:
<%= form_tag '/inbox/search', :method => 'get' do %>
<p>
<%= search_field_tag :Search, params[:search] %>
<%= submit_tag "Search", :name => nil %>
</p>
<% end %>
应修复您的path helper
问题。至于你为什么会收到这个错误,看起来inbox_search_path
希望你传递id
所以要么你改变了你的路线文件,要么你需要退回你的服务器,或者你需要粘贴你的html文件的其余部分。