named-routing

Using named routes with parameters and form_tag

a 夏天 提交于 2020-01-22 20:30:09
问题 I'm trying to create a simple search form in Rails, but I think I'm missing something. I have a named route for search: map.search ":first_name/:last_name", :controller => "home", :action => "search" I'm trying to use that in my search form: <% form_tag(search_path, :method => 'get') do %> <%= text_field_tag(:first_name) %> <%= text_field_tag(:last_name) %> <%= submit_tag("Search") %> <% end %> But when I load up the search form I get an ActionController::RoutingError: search_url failed to

How to generate the proper `url_for` a nested resource?

*爱你&永不变心* 提交于 2019-12-06 08:27:29
问题 I am using Ruby on Rails 3.2.2 and I would like to generate a proper url_for URL for a nested resource. That is, I have: # config/routes.rb resources :articles do resources :user_associations end # app/models/article.rb class Article < ActiveRecord::Base ... end # app/models/articles/user_association.rb class Articles::UserAssociation < ActiveRecord::Base ... end Note : generated named routes are like article_user_associations , article_user_association , edit_article_user_association , ...

More-efficient way to pass the Rails params hash to named route

不问归期 提交于 2019-12-04 13:55:13
问题 I need a more-efficient way to pass the params hash to a named route, including the ability to add/remove/modify a key/value pair. Adding a key (the :company symbol), while preserving the remainder of the params hash (manually specify each symbol/value): # adds the company filter link_to_unless params[:company]==company, company, jobs_path(:company=>company, :posted=>params[:posted],:sort=>params[:sort],:dir=>params[:dir]) Removing a key (eliminates the :company symbol), while preserving the

Using named routes with parameters and form_tag

妖精的绣舞 提交于 2019-12-04 06:47:01
I'm trying to create a simple search form in Rails, but I think I'm missing something. I have a named route for search: map.search ":first_name/:last_name", :controller => "home", :action => "search" I'm trying to use that in my search form: <% form_tag(search_path, :method => 'get') do %> <%= text_field_tag(:first_name) %> <%= text_field_tag(:last_name) %> <%= submit_tag("Search") %> <% end %> But when I load up the search form I get an ActionController::RoutingError: search_url failed to generate from {:action=>"search", :controller=>"home"} - you may have ambiguous routes, or you may need

Named routes in mounted rails engine

寵の児 提交于 2019-11-30 11:18:20
问题 I'm making a small rails engine which I mount like this: mount BasicApp::Engine => "/app" Using this answer I have verified that all the routes in the engine are as the should be: However - when I (inside the engine) link to a named route (defined inside the engine) I get this error undefined local variable or method `new_post_path' for #<#<Class:0x000000065e0c08>:0x000000065d71d0> Running "rake route" clearly verifies that "new_post" should be a named path, so I have no idea why Rails (3.1.0

Named routes in mounted rails engine

时光怂恿深爱的人放手 提交于 2019-11-29 23:40:08
I'm making a small rails engine which I mount like this: mount BasicApp::Engine => "/app" Using this answer I have verified that all the routes in the engine are as the should be: However - when I (inside the engine) link to a named route (defined inside the engine) I get this error undefined local variable or method `new_post_path' for #<#<Class:0x000000065e0c08>:0x000000065d71d0> Running "rake route" clearly verifies that "new_post" should be a named path, so I have no idea why Rails (3.1.0) can't figure it out. Any help is welcome my config/route.rb (for the engine) look like this BasicApp: