devise wrongly routes site controller - ruby-on-rails-3

I have a problem with devise 1.1.5 on rails 3.0.3.
I have a controller "site" with an action "home". When I do a "rake routes" everything is as it should be, but when I click in my site on the sign_up link, it returns an error:
No route matches {:action=>"home", :controller=>"devise/site"}
This is correct the controller should be "site", not "devise/site".
This is in my routes.rb:
resources :articles
get "site/home"
get "site/about"
devise_for :users
But when I look with "rake routes" everything looks fine. Any ideas? Thanks!
articles GET /articles(.:format) {:action=>"index", :controller=>"articles"}
POST /articles(.:format) {:action=>"create", :controller=>"articles"}
new_article GET /articles/new(.:format) {:action=>"new", :controller=>"articles"}
edit_article GET /articles/:id/edit(.:format) {:action=>"edit", :controller=>"articles"}
article GET /articles/:id(.:format) {:action=>"show", :controller=>"articles"}
PUT /articles/:id(.:format) {:action=>"update", :controller=>"articles"}
DELETE /articles/:id(.:format) {:action=>"destroy", :controller=>"articles"}
site_home GET /site/home(.:format) {:action=>"home", :controller=>"site"}
site_about GET /site/about(.:format) {:action=>"about", :controller=>"site"}
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session GET /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
user_password POST /users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_user_password GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_user_password GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
user_registration POST /users(.:format) {:action=>"create", :controller=>"devise/registrations"}
new_user_registration GET /users/sign_up(.:format) {:action=>"new", :controller=>"devise/registrations"}
edit_user_registration GET /users/edit(.:format) {:action=>"edit", :controller=>"devise/registrations"}
PUT /users(.:format) {:action=>"update", :controller=>"devise/registrations"}
DELETE /users(.:format) {:action=>"destroy", :controller=>"devise/registrations"}
root /(.:format) {:action=>"home", :controller=>"site"}

What is the code for your sign up link?
Try changing your routes.rb to (I think the way 'home' and 'about' are currently describe might be causing the error):
devise_for :users
resources :sites do
get :home, :on => :member
get :about, :on => :member
end
resources :articles
also remember to set your root path so that when user does get signed-in they are directed to correct view.

Related

link_to paths not linking after adding bootstrap

I have a rails application that is built on the SAAS stripe application that is hosted here:
http://railsapps.github.com/rails-recurly-subscription-saas/
I added twitter bootstrap to this and my paths are no longer creating links.
For instance my route file has:
resources :users
however no users_path is creating a link to the location in my erb files
<%= link_to 'Admin', users_path %>
Any ideas or additional information i could provide?
Rake routes:
E:\Sites>rake routes
stripe_event /stripe StripeEvent::Engine
content_gold GET /content/gold(.:format) content#gold
content_silver GET /content/silver(.:format) content#silver
content_platinum GET /content/platinum(.:format) content#platinum
root / home#index
root / home#index
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) registrations#cancel
user_registration POST /users(.:format) registrations#create
new_user_registration GET /users/sign_up(.:format) registrations#new
edit_user_registration GET /users/edit(.:format) registrations#edit
PUT /users(.:format) registrations#update
DELETE /users(.:format) registrations#destroy
update_plan PUT /update_plan(.:format) registrations#update_plan
update_card PUT /update_card(.:format) registrations#update_card
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
So this seems to be caused by bad references to images that occured when i added an asset/images directory from the wrapbootstrap template.
I added this line to my application.rb file below the config.assets.enabled=true
config.assets.paths << Rails.root.join("app", "images")
To get my images to show up after this I had to change them to be in rails format, so background: img(..) became
background: image-url('images/social_icons.png')

Devise with restful user

I have devise and users controller
routes.rb
devise_for :users
resources :users do
resources :blogs
end
users_controller.rb
class UsersController < ApplicationController
respond_to :html, :xml, :json
def create
#user = User.create(params[:user])
end
def show
#user = User.find(params[:id])
#asset = Asset.find(params[:id])
respond_with [#user, #asset]
end
def update
#user = User.find(params[:id])
#user.update_attributes(params[:user])
respond_with #user
end
end
when I visit http://localhost:3000/users/sign_out
I get
ActiveRecord::RecordNotFound in UsersController#show
Couldn't find User with id=sign_out
update:
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
Any solution?
It happens because your session is destroyed by DELETE method.
From your rake routes:
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
And when you visit http://localhost:3000/users/sign_out, you use GET
You can change method in initializers/devise.rb. Just set config.sign_out_via to :get
Your routes.rb file and your generated routes don't appear to match. Routes are evaluated in order, and the first that matches is served.
You need your devise routes before your custom user routes. Something like this...
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
I'd confirm that your routes file looks like what you posted, because it seems inconsistent.

Resource Routing: short style

here is my config/routes.rb:
Eesoudayo::Application.routes.draw do
resources :articles do
resources :comments
end
end
...which, as you can imagine, generates the following routes:
article_comments GET /articles/:article_id/comments(.:format) {:action=>"index", :controller=>"comments"}
POST /articles/:article_id/comments(.:format) {:action=>"create", :controller=>"comments"}
new_article_comment GET /articles/:article_id/comments/new(.:format) {:action=>"new", :controller=>"comments"}
edit_article_comment GET /articles/:article_id/comments/:id/edit(.:format) {:action=>"edit", :controller=>"comments"}
article_comment GET /articles/:article_id/comments/:id(.:format) {:action=>"show", :controller=>"comments"}
PUT /articles/:article_id/comments/:id(.:format) {:action=>"update", :controller=>"comments"}
DELETE /articles/:article_id/comments/:id(.:format) {:action=>"destroy", :controller=>"comments"}
articles GET /articles(.:format) {:action=>"index", :controller=>"articles"}
POST /articles(.:format) {:action=>"create", :controller=>"articles"}
new_article GET /articles/new(.:format) {:action=>"new", :controller=>"articles"}
edit_article GET /articles/:id/edit(.:format) {:action=>"edit", :controller=>"articles"}
article GET /articles/:id(.:format) {:action=>"show", :controller=>"articles"}
PUT /articles/:id(.:format) {:action=>"update", :controller=>"articles"}
DELETE /articles/:id(.:format) {:action=>"destroy", :controller=>"articles"}
My question is: is there a sexy way to clean a little bit them, giving this result?
article_comments GET /:article_id/(.:format) {:action=>"index", :controller=>"comments"}
POST /:article_id/(.:format) {:action=>"create", :controller=>"comments"}
new_article_comment GET /:article_id/new(.:format) {:action=>"new", :controller=>"comments"}
edit_article_comment GET /:article_id/:id/edit(.:format) {:action=>"edit", :controller=>"comments"}
article_comment GET /:article_id/:id(.:format) {:action=>"show", :controller=>"comments"}
PUT /:article_id/:id(.:format) {:action=>"update", :controller=>"comments"}
DELETE /:article_id/:id(.:format) {:action=>"destroy", :controller=>"comments"}
articles GET /.:format) {:action=>"index", :controller=>"articles"}
POST /.:format) {:action=>"create", :controller=>"articles"}
new_article GET /new(.:format) {:action=>"new", :controller=>"articles"}
edit_article GET /:id/edit(.:format) {:action=>"edit", :controller=>"articles"}
article GET /:id(.:format) {:action=>"show", :controller=>"articles"}
PUT /:id(.:format) {:action=>"update", :controller=>"articles"}
DELETE /:id(.:format) {:action=>"destroy", :controller=>"articles"}
PS: I'm working with Rails 3.x <3
I don't really know if this works, a shot in the dark really:
Eesoudayo::Application.routes.draw do
resources :articles, :path => "/" do
resources :comments, :path => "/"
end
end
I have only tested this using rake routes, it may very well be that everything will explode when you try to launch your server.

Named route from resources takes me to show page instead of delete page

I am using resources :users in routes.rb. This provides the following paths as rake routes unveils.
users GET /users(.:format) {:action=>"index", :controller=>"users"}
POST /users(.:format) {:action=>"create", :controller=>"users"}
new_user GET /users/new(.:format) {:action=>"new", :controller=>"users"}
edit_user GET /users/:id/edit(.:format) {:action=>"edit", :controller=>"users"}
user GET /users/:id(.:format) {:action=>"show", :controller=>"users"}
PUT /users/:id(.:format) {:action=>"update", :controller=>"users"}
DELETE /users/:id(.:format) {:action=>"destroy", :controller=>"users"}
Further, I comment out the legacy wild controller route.
#match ':controller(/:action(/:id(.:format)))'
To add a delete link on my users page I add the following.
<%= link_to "Delete user", user, :method => :delete, :confirm => "Are you sure?" %>
This generated the following html code.
Delete user
I click the link and it takes me to the show page?! What's wrong?
You need to include the default Javascript files for that to work properly:
<%= javascript_include_tag :defaults %>

devise 2 models 2 views problem with path

context:
rails 3.0.3
devise 1.1.5 and 1.2rc
i have following devise rdoc
rails g devise:install
rails g devise user
rails g devise employee
rails g devise:views users
rails g devise:views employees
routes.rb
devise_for :users
devise_for :employees, :path => 'admin'
devise.rb
config.scoped_views = true
rake routes gives
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session GET /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
user_password POST /users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_user_password GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_user_password GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
user_unlock POST /users/unlock(.:format) {:action=>"create", :controller=>"devise/unlocks"}
new_user_unlock GET /users/unlock/new(.:format) {:action=>"new", :controller=>"devise/unlocks"}
GET /users/unlock(.:format) {:action=>"show", :controller=>"devise/unlocks"}
new_employee_session GET /admin/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
employee_session POST /admin/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_employee_session GET /admin/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
employee_password POST /admin/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_employee_password GET /admin/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_employee_password GET /admin/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /admin/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
a mailer views users or employees are
link_to 'Change my password', edit_user_password_url(#resource, :reset_password_token => #resource.reset_password_token)
link_to 'Change my password', edit_employee_password_url(#resource, :reset_password_token => #resource.reset_password_token)
But if i submit form i have this error (for user or employee)
TypeError in Devise/passwords#create
Showing /app/views/users/mailer/reset_password_instructions.html.erb where line #8 raised:
can't convert String into Hash
8: <%= link_to 'Change my password', edit_employee_password_url(#resource, :reset_password_token => #resource.reset_password_token) %>
if you have an idea ?
Initialy posted Mar 7 2011
The solution are in application_controller.rb.
add
ActionMailer::Base.default_url_options[:host] = "http://domain.com"