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
Related
I'm fairly new to Ruby and Rails and this has been an issue I can't resolve on my own:
I'm working on an existing website, running on an older version of Rails and Ruby 1.9.3.
I'm trying to change the details for a certain user, but sometimes in the linking I don't get http://127.0.0.1:3000/users/firstname.lastname but http://127.0.0.1:3000/users?id=firstname.lastname.
This is the code for the links I have:
<li><%= link_to "Remove this user", user_path(#person[:uid]), :confirm => 'Are you sure you want to delete ' + #person[:uid] + '?',:method => :delete ,:title => "Delete user from LDAP" %></li>
<li><%= link_to "Edit this user", edit_userdetails_path(id:#username[:UserID]) %></li>
<li><%= link_to "Add to group", group_path %></li>
<li><%= link_to "Change password", change_pwd_path(#person[:uid]) %></li>
The first and 3rd link work like they should, the 2nd and 4th link have the behavior as described with the ?id= in the url.
This is what's in my routes file:
resources :posts
resources :timesheets
resources :personal_bugs, :only => [:new, :create, :destroy]
resources :sessions, :only => [:new, :create, :destroy]
resources :passwords, :only => [:new, :create]
resources :users, :constraints => { :id => /[0-9A-Za-z\-\.]+/ }
resources :computers
resources :userdetails, :constraints => { :id => /[0-9A-Za-z\-\.]+/ }
resources :bz2refs, :only => [:index, :update]
resources :bz2ref_activities
resources :sessions do
collection do
get :reset_password
get :recovery
end
end
resources :bz2ref_resources do
collection do
get :remove
get :restore
end
end
get "userdetails" => "userdetails#index", :as => "userdetails"
get "edit_userdetails" => "userdetails#edit", :as => "edit_userdetails"
get "log_out" => "sessions#destroy", :as => "log_out"
get "log_in" => "sessions#new", :as => "log_in"
get "change_pwd" => "passwords#new", :as => "change_pwd"
post "search" => "pages#search", :as => "search"
get "search" => "pages#search", :as => "search"
get "help" => "pages#help", :as => "help"
get "admin_urls" => "pages#admin_urls", :as => "admin_urls"
get "report" => "timesheets#report", :as => "report"
post "report" => "timesheets#report", :as => "report"
get "incomplete" => "timesheets#incomplete", :as => "incomplete"
post "incomplete" => "timesheets#incomplete", :as => "incomplete"
get "check" => "timesheets#check", :as => "check"
post "check" => "timesheets#check", :as => "check"
get "export" => "timesheets#export", :as => "export"
get "group" => "users#group", :as => "group"
get "group_show" => "users#group_show", :as => "group_show"
post "group_add" => "users#group_add", :as => "group_add"
get "computer_wake" => "computers#wake", :as => "computer_wake"
get "mirror_users" => "users#mirror", :as => "mirror_users"
get "kiosk" => "posts#latest", :as=> "kiosk"
get "lookupbug" => "timesheets#lookupbug", :as =>"lookupbug"
I call upon userdetails controller from users and then after editing I want to go back from userdetails --> users.
That is because you give an id parameter in the path.
So for example:
user_path(#person[:uid]) => localhost/users/firstname.lastname
user_path(id: #person[:uid]) => localhost/users?id=firstname.lastname
To fix the second link you need to change from edit_userdetails_path(id:#username[:UserID]) to edit_userdetails_path(#username[:UserID]), without the id.
I solved the issue by creating the hyperlink this way:
<li><%= link_to "Edit this user", controller: "userdetails", action: "edit", id: #username[:UserID] %></li>
This way it works!
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)
I'm trying to implement custom dynamic error pages following this post:
http://www.perfectline.co.uk/blog/custom-dynamic-error-pages-in-ruby-on-rails
I did exactly what the blog post says. I included config.action_controller.consider_all_requests_local = false in my environment.rb. But is not working.
My browser shows:
Routing Error
No route matches "/555" with {:method=>:get}
So, it looks like the rescues are not fired.
I get the following in my log file:
ActionController::RoutingError (No route matches "/555" with {:method=>:get}):
Rendering rescues/layout (not_found)
Is there some routing interfering with the code? I'm not sure what to look for. I'm running rails 2.3.5.
Here is the routes.rb file:
ActionController::Routing::Routes.draw do |map|
# routing van property-url
map.connect 'buy/:property_type_plural/:province/:city/:address/:house_number', :controller => 'properties' , :action => 'show', :id => 'whatever'
map.myimmonatie 'myimmonatie' , :controller => 'myimmonatie/properties', :action => 'index'
map.login "login", :controller => "user_sessions", :action => "create", :conditions => {:method => :post}
map.login "login", :controller => "user_sessions", :action => "new"
map.logout "logout", :controller => "user_sessions", :action => "destroy"
map.buy "buy", :controller => 'buy'
map.sell "sell", :controller => 'sell'
map.home "home", :controller => 'home'
map.disclaimer "disclaimer", :controller => 'disclaimer'
map.sign_up "sign_up", :controller => 'users', :action => :new
map.contact "contact", :controller => 'contact'
map.resources :user_sessions
map.resources :contact
map.resources :password_resets
map.resources :messages
map.resources :users, :only => [:index,:new,:create,:activate,:edit,:profile,:password]
map.resources :images
map.resources :activation , :only => [:new,:resend]
map.resources :email
map.resources :properties, :except => [:index,:destroy]
map.namespace :admin do |admin|
admin.resources :users
admin.resources :properties
admin.resources :order_items, :as => :orders
admin.resources :blog_posts, :as => :blog
end
map.connect 'myimmonatie/:action' , :controller => 'users', :id => 'current', :requirements => {:action => /(profile)|(password)|(email)/}
map.namespace :myimmonatie do |myimmonatie|
myimmonatie.resources :messages, :controller => 'messages'
myimmonatie.resources :password, :as => "password", :controller => 'users', :action => 'password'
myimmonatie.resources :properties , :controller => 'properties'
myimmonatie.resources :orders , :only => [:index,:show,:create,:new]
end
map.root :controller => "home"
map.connect ':controller/:action'
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end
ActionController::Routing::Translator.translate_from_file('config','i18n-routes.yml')
The code works, something is wrong with the line in my environment.rb
config.action_controller.consider_all_requests_local = false
It seems to be overridden somewhere.
So, CASE CLOSED, thanks!
Rails detects when you are browsing with ip 127.0.0.1 and shows you the development environment errors even if you are in production environment. You should try accessing from a different machine to get the proper errors.
I'm trying to get this link:
<%= link_to('Edit', :action => 'manage', :id => user) %>
even tried explicitly <%= link_to('Edit', {:controller => 'users', :action => 'manage', :id => user}, :method => :get) %>
to show the link in HTML as
'/users/manage/1' or '/users/1/manage'
but it shows up as
'/users/manage?id=1'
I can see in my routes:
manage_users GET /users/manage(.:format) {:action=>"manage", :controller=>"users"}
...
edit_user GET /users/:id/edit(.:format) {:action=>"edit", :controller=>"users"}
so I added a map.connect, but it was added to users
users GET /users/manage/:id(.:format) {:action=>"manage", :controller=>"users"}
but without any success. The link is still '/users/manage?id=1'
This doesn't work anymore than the above.
GET /users/:id/manage(.:format) {:action=>"manage", :controller=>"users"}
Now, when I put the :action in link_to, to 'edit' i.e.
<%= link_to('Edit', :action => 'edit', :id => user) %>
The routes.rb edit_user GET /users/:id/edit/(.:format) works, with a link showing up of
'/users/1/edit'
How do I get my link_to to show the same link when it is 'manage' instead of 'edit', i.e. showing a link of 'users/1/manage' instead of '/users/manage?id=1'??? Is it because my above map.connect is being added to users, when it should be added to 'manage_users'?
Thank for the help. I'll be trying to figure it out.
Peace.
BTW, /users/manage?id=1 works, I just want the proper rewrite link to click on.
EDIT routes.rb
map.resources :users, :collection => {:manage => :get}
#map.manage_user '/users/:id/manage', :controller => :users, :action => :manage
#map.resources :users, :member => { :manage => :get }
#map.connect 'users/manage/:id(.:format)', :controller => 'users', :action => 'manage', :conditions => { :method => :get }
map.resources :categories
map.resources :posts
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
so I added a map.connect, but it was added to users
I suspect you added map.connect after other definitions, which would give it lowest priority. Try putting it in the beginning of routes.rb file.
You can also use named routes to avoid confusion:
map.manage_user '/users/:id/manage', :controller => :users, :action => :manage
and then refer it as
link_to 'Manage', manage_user_path(:id => user)
edit
If that doesn't work, please show your routes.rb file.
You should change collection to member in your routes.rb when defining map.resources :users. Then you'll get nice /users/1/manage link.
Also, when creating a link try this:
<%= link_to 'Manage', manage_user_path(user) %>
I have a page model and a pages_controller within an admin namespace. My routes file looks like this:
map.resources :pages, :only => [:index,:show]
map.resources :admin, :only => [:index]
map.namespace :admin do |admin|
admin.resources :pages
end
I am not able to figure out the correct method to create a link for deleting a page (In the same way the scaffold generator generates a delete link on the index page).
Any ideas on the correct parameters for the link_to function?
TIA,
Adam
rake routes is your friend here. It'll spit out the list of your generated routes - particularly useful if you have a bunch of nested or custom routes.
the paths will be
admin_pages_path #(with GET) routes to :controller => 'admin/pages', :action => 'index'
admin_pages_path #(with POST) routes to :controller => 'admin/pages', :action => 'create'
new_admin_page_path #(with GET) routes to :controller => 'admin/pages', :action => 'new'
edit_admin_page_path(:id) #(with GET) routes to :controller => 'admin/pages', :action => 'edit'
admin_page_path(:id) #(with GET) routes to :controller => 'admin/pages', :action => 'show'
admin_page_path(:id) #(with PUT) routes to :controller => 'admin/pages', :action => 'update'
admin_page_path(:id) #(with DELETE) routes to :controller => 'admin/pages', :action => 'delete'
Your link_to for delete should therefore be:
<%= link_to("delete page", admin_page_path(#page), :confirm => "sure you want to delete this page?", :method => :delete) %>
Note that Rails will work its magic calling to_param on #page, so that you don't have to specify #page.id - useful for an example like this as you often want to use permalinks for 'pages'.