How do I set the path?
I get the following error when I run my rails application:
No route matches {:action=>"search", :controller=>"inbox"} missing required keys: [:id]
I think this has to do with my routes.rb file.
I am working on a search bar and every time I search, it loops back to the main page since I do not have a path set.
This is my index.erb.html file.
<%= form_tag inbox_search_path, :method => 'get' do %>
<p>
<%= search_field_tag :Search, params[:search] %>
<%= submit_tag "Search", :name => nil %>
</p>
<% end %>
And this is my routes.rb file.
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
This is my relevant part of route.rb file.
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'
Add this route to your routes.rb
get 'inbox/search' => 'inbox#search', :as => inbox_search
it looks like your route has a spelling error which could cause it to fail.
get 'inbox/search' => 'inbox#seaarch', :as => 'inbox_search'
^
So changing your form_tag to this:
<%= form_tag '/inbox/search', :method => 'get' do %>
<p>
<%= search_field_tag :Search, params[:search] %>
<%= submit_tag "Search", :name => nil %>
</p>
<% end %>
should fix your path helper problem. as to why you're getting that error it looks like inbox_search_path is expecting you to pass in an id so either you changed your route file, you need to bounce your server, or you need to paste the rest of your html file.
I am getting this error: ActionController::UrlGenerationError in ContactUs::Contacts#new, using this gem https://github.com/jdutil/contact_us .
The error: No route matches {:controller=>"contact_us/pages", :action=>"home"}
Where the error is occurring:
.col-xs-8
%ul
%li
= link_to "Home", :controller => 'pages', :action => 'home'
%li
= link_to "About", :controller => 'pages', :action => 'about'
%li
My routes:
devise_for :users
resources :available_times
root :to => "pages#home"
get 'about' => 'pages#about'
get 'pricing' => 'pages#pricing'
get 'users/my-bookings' => 'available_times#index'
get 'users/x34' => 'available_times#create'
get 'users/test_func/:id/:time' => 'available_times#test_func'
Gem routes
Rails.application.routes.draw do
resources :contacts,
:controller => 'contact_us/contacts',
:only => [:new, :create]
get '/contact-us' => 'contact_us/contacts#new', :as => :contact_us
end
Looks like you have a scoping issue. The view is rendered in the contact_us scope and calling a controller in that scope will have it look for it in contact_us/ rather than the entire app. I'm no big fan of using the :controller => 'pages', :action => 'home' for routes generation directly, try and use the path helper instead. It will probably work better.
= link_to "Home", root_path
= link_to "About", about_path
In routes:
get 'about' => 'pages#about', as: :about
I'm trying to pass some values through a link and I want them to be invisible. These are the options I've tried:
<%= link_to 'Add comment', :controller => :comments, :action => :new, :idea_id => #idea.id, :user_id => #idea.user.id, :method => :post %>
<%= link_to 'Add comment',{ :controller => :comments, :action => :new, :idea_id => #idea.id, :user_id => #idea.user.id}, :method => :post %>
<%= link_to 'Add comment', :controller => :comments, :action => :new, :idea_id => #idea.id, :user_id => #idea.user.id, %>
<%= link_to 'Add comment', new_comment_path, :idea_id => #idea.id, :user_id => #idea.user.id, :method => :post %>
First option - treats method as a parameter:
http://localhost:2000/comments/new?idea_id=1&method=post&user_id=1
Second option - goes like this: http://localhost:2000/comments/new?idea_id=1&user_id=1
and also causes routing error: "Routing Error No route matches "/comments/new"
Third option - loads the form, but of course is like: http://localhost:2000/comments/new?idea_id=1&user_id=1
Fourth option - looks good (http://localhost:2000/comments/new) but the same routing error like the second one.
What am I doing wrong?
Thanks in advance.
PS
I was asked to give my routes, so here they are:
resources :rights
resources :comments
resources :ideas
resources :users
resources :sessions, :only => [:new, :create, :destroy]
root :to => 'main#home'
#match '/comments/new' => "comments#new" # this doesn't help
match '/home', :to => 'main#home'
match '/contact', :to => 'main#contact'
match '/signin', :to => 'sessions#new'
match '/signout', :to => 'sessions#destroy'
match '/signup', :to => 'users#new'
If you have RESTful routes
<%= link_to 'Add comment', new_comment_path,
:idea_id => #idea.id, :user_id => #idea.user.id, :method => :post %>
should be
<%= link_to 'Add comment', comments_path,
:idea_id => #idea.id, :user_id => #idea.user.id, :method => :post %>
As others have said, it sounds like you have a problem in your routes file. Either check if you have the resource :comments defined or post your routes file here and we'll help you out. It's possible that it's not working because you are trying to POST...
If you want 'invisible' variables (I assume you mean that you do not want the variables to appear in the URL), you'll have to POST to the page rather than just link to it. In this case, your second example is the best bet. It goes against convention to POST to /new so that could be what is causing the 'no routes' error if you're using resource :comments
Give this a try in your routes.rb:
match '/comments/new' => "comments#new"
Give that a try, it should load the correct page and give you access to the variables you passed through to it through params.
Please note, that this goes wildly against convention. Is there a reason why you don't want those variables to appear in the URL? It's likely there's a better way of doing what you're thinking and if you explain we can advise you as best as we can.
Have you properly defined the routes?
Can you show how they are?
You should have something like this for that to work: resource :comments
Also, in general /new works with a GET, and a POST is sent when creating...
The method is part of html_options, you need to separate the two hashes like so:
<%= link_to 'Add comment', {:controller => :comments, :action => :new, :idea_id => #idea.id, :user_id => #idea.user.id}, :method => :post %>
I have this in my routes:
get '/boutique/new' => 'stores#new', :as => :new_store, :constraints => { :id => /[a-z0-9_-]/ }
post '/boutique' => 'stores#create', :as => :create_store, :constraints => { :id => /[a-z0-9_-]/ }
get '/:shortname' => 'stores#show', :as => :store, :constraints => { :id => /[a-z0-9_-]/ }
get '/:shortname/edit' => 'stores#edit', :as => :edit_store, :constraints => { :id => /[a-z0-9_-]/ }
put '/:shortname' => 'stores#update', :as => :update_store, :constraints => { :id => /[a-z0-9_-]/ }
delete '/:shortname' => 'stores#delete', :as => :destroy_store, :constraints => { :id => /[a-z0-9_-]/ }
Is there a cleaner way to do the same? It doesn't look any elegant and even less if I add some more controls/actions to it.
Thank you.
Your best option would be to stick to the standard resource routes. If anyone else ever needs to work on the application you're building, they'll thank you.
That said, if you really need this routing setup (for whatever reason), try the following:
controller :stores do
constraints :id => /[a-z0-9_-]/ do
get '/boutique/new' => :new, :as => :new_store
post '/boutique' => :create, :as => :create_store
get '/:shortname' => :show, :as => :store
get '/:shortname/edit' => :edit, :as => :edit_store
put '/:shortname' => :update, :as => :update_store
delete '/:shortname' => :delete, :as => :destroy_store
end
end
I haven't actually tested it, but that should work fine.
the link:
<li><%= link_to "Map", :controller => :info, :action => :map %></li>
routes:
resources :link_pages
resources :services
resource :user_session
resource :account, :controller => "users"
resources :password_resets
resources :users
resources :addresses
resources :info
match "/home", :to => 'info#home'
match "/register", :to => 'users#new'
root :to => 'info#home'
but when I click "Map", it thinks I want to go to info#show =\
match ':controller(/:action(/:id(.:format)))'
Try <%= link_to "Map", {:controller => :info, :action => :map} %> (notice the Hash)