Formtastic remote form - ruby-on-rails

I am using Formtastic and I am trying to set up a remote form to access the edit action without leaving the current page and going to the /1/edit type url.
My form is as follows:
<%= semantic_form_for shipdr_website, :url => edit_shipdr_website_path(shipdr_website), :html => { :method => :post }, :remote => true do |f| %>
<%= f.input :name, :input_html => { :value => shipdr_website.name } %>
<%= f.input :url, :input_html => { :value => shipdr_website.url } %>
<%= f.input :api_key, :input_html => { :value => shipdr_website.api_key } %>
<%= f.actions %>
<% end %>
The view is located under shipdr/dash/websites, the controller for the dash view does not have an edit action so I need to use the remote form to access the edit method of a different controller.
The form displays and the page loads without displaying any errors, however, when I click on the 'Create Website' button nothing is happening. If I remove the remote => true part of line 1 then I get No route matches [POST] "/shipdr/websites/14/edit" when I click on the button.
Here are my routes using rake routes:
shipdr_dashboard_dashboard /shipdr/dashboard/dashboard(.:format) {:controller=>"shipdr/dashboard", :action=>"dashboard"}
shipdr_websites GET /shipdr/websites(.:format) {:action=>"index", :controller=>"shipdr/websites"}
POST /shipdr/websites(.:format) {:action=>"create", :controller=>"shipdr/websites"}
new_shipdr_website GET /shipdr/websites/new(.:format) {:action=>"new", :controller=>"shipdr/websites"}
edit_shipdr_website GET /shipdr/websites/:id/edit(.:format) {:action=>"edit", :controller=>"shipdr/websites"}
shipdr_website GET /shipdr/websites/:id(.:format) {:action=>"show", :controller=>"shipdr/websites"}
PUT /shipdr/websites/:id(.:format) {:action=>"update", :controller=>"shipdr/websites"}
DELETE /shipdr/websites/:id(.:format) {:action=>"destroy", :controller=>"shipdr/websites"}
shipdr_carriers GET /shipdr/carriers(.:format) {:action=>"index", :controller=>"shipdr/carriers"}
POST /shipdr/carriers(.:format) {:action=>"create", :controller=>"shipdr/carriers"}
new_shipdr_carrier GET /shipdr/carriers/new(.:format) {:action=>"new", :controller=>"shipdr/carriers"}
edit_shipdr_carrier GET /shipdr/carriers/:id/edit(.:format) {:action=>"edit", :controller=>"shipdr/carriers"}
shipdr_carrier GET /shipdr/carriers/:id(.:format) {:action=>"show", :controller=>"shipdr/carriers"}
PUT /shipdr/carriers/:id(.:format) {:action=>"update", :controller=>"shipdr/carriers"}
DELETE /shipdr/carriers/:id(.:format) {:action=>"destroy", :controller=>"shipdr/carriers"}
shipdr_countries GET /shipdr/countries(.:format) {:action=>"index", :controller=>"shipdr/countries"}
POST /shipdr/countries(.:format) {:action=>"create", :controller=>"shipdr/countries"}
new_shipdr_country GET /shipdr/countries/new(.:format) {:action=>"new", :controller=>"shipdr/countries"}
edit_shipdr_country GET /shipdr/countries/:id/edit(.:format) {:action=>"edit", :controller=>"shipdr/countries"}
shipdr_country GET /shipdr/countries/:id(.:format) {:action=>"show", :controller=>"shipdr/countries"}
PUT /shipdr/countries/:id(.:format) {:action=>"update", :controller=>"shipdr/countries"}
DELETE /shipdr/countries/:id(.:format) {:action=>"destroy", :controller=>"shipdr/countries"}
shipdr_shipping_groups GET /shipdr/shipping_groups(.:format) {:action=>"index", :controller=>"shipdr/shipping_groups"}
POST /shipdr/shipping_groups(.:format) {:action=>"create", :controller=>"shipdr/shipping_groups"}
new_shipdr_shipping_group GET /shipdr/shipping_groups/new(.:format) {:action=>"new", :controller=>"shipdr/shipping_groups"}
edit_shipdr_shipping_group GET /shipdr/shipping_groups/:id/edit(.:format) {:action=>"edit", :controller=>"shipdr/shipping_groups"}
shipdr_shipping_group GET /shipdr/shipping_groups/:id(.:format) {:action=>"show", :controller=>"shipdr/shipping_groups"}
PUT /shipdr/shipping_groups/:id(.:format) {:action=>"update", :controller=>"shipdr/shipping_groups"}
DELETE /shipdr/shipping_groups/:id(.:format) {:action=>"destroy", :controller=>"shipdr/shipping_groups"}
shipdr_shipping_rules GET /shipdr/shipping_rules(.:format) {:action=>"index", :controller=>"shipdr/shipping_rules"}
POST /shipdr/shipping_rules(.:format) {:action=>"create", :controller=>"shipdr/shipping_rules"}
new_shipdr_shipping_rule GET /shipdr/shipping_rules/new(.:format) {:action=>"new", :controller=>"shipdr/shipping_rules"}
edit_shipdr_shipping_rule GET /shipdr/shipping_rules/:id/edit(.:format) {:action=>"edit", :controller=>"shipdr/shipping_rules"}
shipdr_shipping_rule GET /shipdr/shipping_rules/:id(.:format) {:action=>"show", :controller=>"shipdr/shipping_rules"}
PUT /shipdr/shipping_rules/:id(.:format) {:action=>"update", :controller=>"shipdr/shipping_rules"}
DELETE /shipdr/shipping_rules/:id(.:format) {:action=>"destroy", :controller=>"shipdr/shipping_rules"}
shipdr_shipping_methods GET /shipdr/shipping_methods(.:format) {:action=>"index", :controller=>"shipdr/shipping_methods"}
POST /shipdr/shipping_methods(.:format) {:action=>"create", :controller=>"shipdr/shipping_methods"}
new_shipdr_shipping_method GET /shipdr/shipping_methods/new(.:format) {:action=>"new", :controller=>"shipdr/shipping_methods"}
edit_shipdr_shipping_method GET /shipdr/shipping_methods/:id/edit(.:format) {:action=>"edit", :controller=>"shipdr/shipping_methods"}
shipdr_shipping_method GET /shipdr/shipping_methods/:id(.:format) {:action=>"show", :controller=>"shipdr/shipping_methods"}
PUT /shipdr/shipping_methods/:id(.:format) {:action=>"update", :controller=>"shipdr/shipping_methods"}
DELETE /shipdr/shipping_methods/:id(.:format) {:action=>"destroy", :controller=>"shipdr/shipping_methods"}
shipdr_ship_filters GET /shipdr/ship_filters(.:format) {:action=>"index", :controller=>"shipdr/ship_filters"}
POST /shipdr/ship_filters(.:format) {:action=>"create", :controller=>"shipdr/ship_filters"}
new_shipdr_ship_filter GET /shipdr/ship_filters/new(.:format) {:action=>"new", :controller=>"shipdr/ship_filters"}
edit_shipdr_ship_filter GET /shipdr/ship_filters/:id/edit(.:format) {:action=>"edit", :controller=>"shipdr/ship_filters"}
shipdr_ship_filter GET /shipdr/ship_filters/:id(.:format) {:action=>"show", :controller=>"shipdr/ship_filters"}
PUT /shipdr/ship_filters/:id(.:format) {:action=>"update", :controller=>"shipdr/ship_filters"}
DELETE /shipdr/ship_filters/:id(.:format) {:action=>"destroy", :controller=>"shipdr/ship_filters"}
shipdr_zones GET /shipdr/zones(.:format) {:action=>"index", :controller=>"shipdr/zones"}
POST /shipdr/zones(.:format) {:action=>"create", :controller=>"shipdr/zones"}
new_shipdr_zone GET /shipdr/zones/new(.:format) {:action=>"new", :controller=>"shipdr/zones"}
edit_shipdr_zone GET /shipdr/zones/:id/edit(.:format) {:action=>"edit", :controller=>"shipdr/zones"}
shipdr_zone GET /shipdr/zones/:id(.:format) {:action=>"show", :controller=>"shipdr/zones"}
PUT /shipdr/zones/:id(.:format) {:action=>"update", :controller=>"shipdr/zones"}
DELETE /shipdr/zones/:id(.:format) {:action=>"destroy", :controller=>"shipdr/zones"}
new_admin_user_session GET /admin_users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
admin_user_session POST /admin_users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_admin_user_session DELETE /admin_users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
admin_user_password POST /admin_users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_admin_user_password GET /admin_users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_admin_user_password GET /admin_users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /admin_users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
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 DELETE /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
user_omniauth_callback /users/auth/:action/callback(.:format) {:action=>/google/, :controller=>"omniauth/omniauth_callbacks"}
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"}
cancel_user_registration GET /users/cancel(.:format) {:action=>"cancel", :controller=>"devise/registrations"}
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"}
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"}
pages_contact GET /pages/contact(.:format) {:controller=>"pages", :action=>"contact"}
pages_pricing GET /pages/pricing(.:format) {:controller=>"pages", :action=>"pricing"}
pages_features GET /pages/features(.:format) {:controller=>"pages", :action=>"features"}
pages_howitworks GET /pages/howitworks(.:format) {:controller=>"pages", :action=>"howitworks"}
pages_home GET /pages/home(.:format) {:controller=>"pages", :action=>"home"}
settings /settings(.:format) {:controller=>"pages", :action=>"settings"}
GET /shipdr/dashboard/dashboard(.:format) {:controller=>"shipdr/dashboard", :action=>"dashboard"}
shipdr_dashboard_rules GET /shipdr/dashboard/rules(.:format) {:controller=>"shipdr/dashboard", :action=>"rules"}
shipdr_dashboard_ship GET /shipdr/dashboard/ship(.:format) {:controller=>"shipdr/dashboard", :action=>"ship"}
shipdr_dashboard_validate GET /shipdr/dashboard/validate(.:format) {:controller=>"shipdr/dashboard", :action=>"validate"}
shipdr_dashboard_analytics GET /shipdr/dashboard/analytics(.:format) {:controller=>"shipdr/dashboard", :action=>"analytics"}
shipdr_dashboard_carriers GET /shipdr/dashboard/carriers(.:format) {:controller=>"shipdr/dashboard", :action=>"carriers"}
shipdr_dashboard_websites GET /shipdr/dashboard/websites(.:format) {:controller=>"shipdr/dashboard", :action=>"websites"}
root / {:controller=>"pages", :action=>"home"}
Any help figuring this out would be appreciated.

Have you checked your routes.rb file? Give us the rake routes info
Is your controller setup for ajax requests?
Do you have the necessary javascript that acts upon the semantic form?
These are things to look into to get your form working.
Check out https://gist.github.com/548387?file=tickets_controller.rb to get an idea of hwat you need.

Related

Generating Paths and URLs from Code in rails

If I put this in route.rb get '/products/:id', to: 'products#edit' edit action should be called when the url format is /patients/:id does this mean it will be redirected to edit page? I tried this and it is not redirecting.
This is my rake routes output
admin GET /admin(.:format) {:action=>"index", :controller=>"admin"}
GET /products/:id(.:format) {:controller=>"products", :action=>"edit"}
login GET /login(.:format) {:action=>"new", :controller=>"sessions"}
POST /login(.:format) {:action=>"create", :controller=>"sessions"}
logout DELETE /logout(.:format) {:action=>"destroy", :controller=>"sessions"}
users GET (/:locale)/users(.:format) {:action=>"index", :controller=>"users"}
POST (/:locale)/users(.:format) {:action=>"create", :controller=>"users"}
new_user GET (/:locale)/users/new(.:format) {:action=>"new", :controller=>"users"}
edit_user GET (/:locale)/users/:id/edit(.:format) {:action=>"edit", :controller=>"users"}
user GET (/:locale)/users/:id(.:format) {:action=>"show", :controller=>"users"}
PUT (/:locale)/users/:id(.:format) {:action=>"update", :controller=>"users"}
DELETE (/:locale)/users/:id(.:format) {:action=>"destroy", :controller=>"users"}
orders GET (/:locale)/orders(.:format) {:action=>"index", :controller=>"orders"}
POST (/:locale)/orders(.:format) {:action=>"create", :controller=>"orders"}
new_order GET (/:locale)/orders/new(.:format) {:action=>"new", :controller=>"orders"}
edit_order GET (/:locale)/orders/:id/edit(.:format) {:action=>"edit", :controller=>"orders"}
order GET (/:locale)/orders/:id(.:format) {:action=>"show", :controller=>"orders"}
PUT (/:locale)/orders/:id(.:format) {:action=>"update", :controller=>"orders"}
DELETE (/:locale)/orders/:id(.:format) {:action=>"destroy", :controller=>"orders"}
line_items GET (/:locale)/line_items(.:format) {:action=>"index", :controller=>"line_items"}
POST (/:locale)/line_items(.:format) {:action=>"create", :controller=>"line_items"}
new_line_item GET (/:locale)/line_items/new(.:format) {:action=>"new", :controller=>"line_items"}
edit_line_item GET (/:locale)/line_items/:id/edit(.:format) {:action=>"edit", :controller=>"line_items"}
line_item GET (/:locale)/line_items/:id(.:format) {:action=>"show", :controller=>"line_items"}
PUT (/:locale)/line_items/:id(.:format) {:action=>"update", :controller=>"line_items"}
DELETE (/:locale)/line_items/:id(.:format) {:action=>"destroy", :controller=>"line_items"}
carts GET (/:locale)/carts(.:format) {:action=>"index", :controller=>"carts"}
POST (/:locale)/carts(.:format) {:action=>"create", :controller=>"carts"}
new_cart GET (/:locale)/carts/new(.:format) {:action=>"new", :controller=>"carts"}
edit_cart GET (/:locale)/carts/:id/edit(.:format) {:action=>"edit", :controller=>"carts"}
cart GET (/:locale)/carts/:id(.:format) {:action=>"show", :controller=>"carts"}
PUT (/:locale)/carts/:id(.:format) {:action=>"update", :controller=>"carts"}
DELETE (/:locale)/carts/:id(.:format) {:action=>"destroy", :controller=>"carts"}
who_bought_product GET (/:locale)/products/:id/who_bought(.:format) {:action=>"who_bought", :controller=>"products"}
products GET (/:locale)/products(.:format) {:action=>"index", :controller=>"products"}
POST (/:locale)/products(.:format) {:action=>"create", :controller=>"products"}
new_product GET (/:locale)/products/new(.:format) {:action=>"new", :controller=>"products"}
edit_product GET (/:locale)/products/:id/edit(.:format) {:action=>"edit", :controller=>"products"}
product GET (/:locale)/products/:id(.:format) {:action=>"show", :controller=>"products"}
PUT (/:locale)/products/:id(.:format) {:action=>"update", :controller=>"products"}
DELETE (/:locale)/products/:id(.:format) {:action=>"destroy", :controller=>"products"}
store /(:locale)(.:format) {:controller=>"store", :action=>"index"}
The route you've got there doesn't do a redirect, it maps the url /patients/:id to the edit action of the PatientsController.
When a user hits the /patients/id url, the edit action will be invoked. By default this tries to render a view with the same name as the action.
If you want to render an edit page, create a view in the /app/views/patients folder called edit.html.erb.
(By the way, the GET /model/:id route is generally used for the show action.)

Ruby on Rails devise http://0.0.0.0:3000/users/sign_out gets routing error

routes.rb =>
Sendemail::Application.routes.draw do
devise_for :users
get "user/index"
get "home/index"
root :to => 'home#index'
end
rake routes =>
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 DELETE /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"}
cancel_user_registration GET /users/cancel(.:format) {:action=>"cancel", :controller=>"devise/registrations"}
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"}
user_confirmation POST /users/confirmation(.:format) {:action=>"create", :controller=>"devise/confirmations"}
new_user_confirmation GET /users/confirmation/new(.:format) {:action=>"new", :controller=>"devise/confirmations"}
GET /users/confirmation(.:format) {:action=>"show", :controller=>"devise/confirmations"}
user_index GET /user/index(.:format) {:controller=>"user", :action=>"index"}
home_index GET /home/index(.:format) {:controller=>"home", :action=>"index"}
root / {:controller=>"home", :action=>"index"}
When i type rails server i get this message every time =>
/home/user1/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.3.4/lib/rack/backports/uri/common_192.rb:53: warning: already initialized constant WFKV
For "http://0.0.0.0:3000/users/sign_out"
Routing Error
No route matches [GET] "/users/sign_out"
What should i do to fix this problem ?
Notice how your routes say /users/sign_out is a DELETE request. Most browsers do not make DELETE requests by default. Just going to that URL would be a GET request to /users/sign_out.
This how to add sign out links should help you get it working.
Add :method => :delete to your signout link.

Rails 3.1 - Devise - CanCan: "../users/sign_out" gets routing error "uninitialized constant UsersController"

"sign_in" works fine but clicking on "sign_out" link locks up during routing (see routes.rb below).
Not sure where to proceed. I'm using RubyMine (IDE) debugger.
I click on a link from layout/applications.html.erb:
<%= link_to('Logout', destroy_user_session_path) %>
RM Debugger watchlist shows: destroy_user_session_path="/user/sign_out"
When I sign_in as a user I breakpoint in "../devise/sessions_controller.rb#sign_in" and that all works
fine when I continue.
The status change gives me a "sign_out" link in my applications.html layout but when I click
there I get above routine error. I don't get breakpoints in "../application_controller.rb"
or "../devise/sessions_controller.rb#sign_out"
Here is routes.rb
Demo::Application.routes.draw do
# replace devise_for :users with:
devise_for :users, :controllers => { :registrations => "devise/registrations" }
get "user/show"
get "user/edit"
get "user/index"
get "user/create"
get "user/update"
get "user/new"
resources :users
resources :orders
resources :carts
resources :line_items
resource :store do
member do
get "store/index"
end
end
match ':controller(/:action(/:id(.:format)))'
root to: 'store#index'
end
And rake:routes
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 DELETE /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
cancel_user_registration GET /users/cancel(.:format) {:action=>"cancel", :controller=>"devise/registrations"}
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"}
user_show GET /user/show(.:format) {:controller=>"user", :action=>"show"}
user_edit GET /user/edit(.:format) {:controller=>"user", :action=>"edit"}
user_index GET /user/index(.:format) {:controller=>"user", :action=>"index"}
user_create GET /user/create(.:format) {:controller=>"user", :action=>"create"}
user_update GET /user/update(.:format) {:controller=>"user", :action=>"update"}
user_new GET /user/new(.:format) {:controller=>"user", :action=>"new"}
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"}
orders GET /orders(.:format) {:action=>"index", :controller=>"orders"}
POST /orders(.:format) {:action=>"create", :controller=>"orders"}
new_order GET /orders/new(.:format) {:action=>"new", :controller=>"orders"}
edit_order GET /orders/:id/edit(.:format) {:action=>"edit", :controller=>"orders"}
order GET /orders/:id(.:format) {:action=>"show", :controller=>"orders"}
PUT /orders/:id(.:format) {:action=>"update", :controller=>"orders"}
DELETE /orders/:id(.:format) {:action=>"destroy", :controller=>"orders"}
carts GET /carts(.:format) {:action=>"index", :controller=>"carts"}
POST /carts(.:format) {:action=>"create", :controller=>"carts"}
new_cart GET /carts/new(.:format) {:action=>"new", :controller=>"carts"}
edit_cart GET /carts/:id/edit(.:format) {:action=>"edit", :controller=>"carts"}
cart GET /carts/:id(.:format) {:action=>"show", :controller=>"carts"}
PUT /carts/:id(.:format) {:action=>"update", :controller=>"carts"}
DELETE /carts/:id(.:format) {:action=>"destroy", :controller=>"carts"}
line_items GET /line_items(.:format) {:action=>"index", :controller=>"line_items"}
POST /line_items(.:format) {:action=>"create", :controller=>"line_items"}
new_line_item GET /line_items/new(.:format) {:action=>"new", :controller=>"line_items"}
edit_line_item GET /line_items/:id/edit(.:format) {:action=>"edit", :controller=>"line_items"}
line_item GET /line_items/:id(.:format) {:action=>"show", :controller=>"line_items"}
PUT /line_items/:id(.:format) {:action=>"update", :controller=>"line_items"}
DELETE /line_items/:id(.:format) {:action=>"destroy", :controller=>"line_items"}
store_index_store GET /store/store/index(.:format) {:controller=>"store/store", :action=>"index"}
store POST /store(.:format) {:action=>"create", :controller=>"stores"}
new_store GET /store/new(.:format) {:action=>"new", :controller=>"stores"}
edit_store GET /store/edit(.:format) {:action=>"edit", :controller=>"stores"}
GET /store(.:format) {:action=>"show", :controller=>"stores"}
PUT /store(.:format) {:action=>"update", :controller=>"stores"}
DELETE /store(.:format) {:action=>"destroy", :controller=>"stores"}
/:controller(/:action(/:id(.:format)))
root / {:controller=>"store", :action=>"index"}
Robin
Change your link to
<%= link_to('Logout', destroy_user_session_path, :method=>'delete') %>
e.g. add `:method=>'delete'

Problem Signing Out with Devise on my App

I am in the process updating my app so I use the Devise gem for authentication. Everything appears to be working great, except for the fact that I can't seem to sign out.
I get the error:
Couldn't find User with ID=sign_out
Parameters:
{"id"=>"sign_out"}
I can trace the error back to the show action in my users controller:
def show
#user = User.find(params[:id])
end
The problem is that I am not sure why it is trying to render the show action for my user. Overall my page has this format:
<% if user_signed_in? %>
<%= render 'shared/feed_home' %>
<% else %>
<%= render 'shared/splash' %>
<% end %>
As per devise instructions, my sign-out path looks like this:
<li><%= link_to "Sign out", destroy_user_session_path %></li>
If a user is not signed in, it should render the splash page which is basically static html. Any suggestions on how to help? Even if you could just put me in the right ball park in terms of the problem that would be much appreciated.
Here is my routes file:
devise_for :users
resources :users do
member do
get :following, :followers, :following_tags, :following_posts
end
end
resources :posts
resources :votes
resources :comments
resources :tags
resources :events
#resources :posts, :only => [:create, :destroy, :show]
resources :relationships, :only => [:create, :destroy]
root :to =>'pages#subscribed'
match '/contact', :to => 'pages#contact'
match '/about', :to => 'pages#about'
match '/live', :to => "pages#home"
match '/voted', :to => 'pages#highest_voted'
match '/signup', :to => 'users#new'
Here is my rake routes:
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 DELETE /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"}
cancel_user_registration GET /users/cancel(.:format) {:action=>"cancel", :controller=>"devise/registrations"}
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"}
following_user GET /users/:id/following(.:format) {:action=>"following", :controller=>"users"}
followers_user GET /users/:id/followers(.:format) {:action=>"followers", :controller=>"users"}
following_tags_user GET /users/:id/following_tags(.:format) {:action=>"following_tags", :controller=>"users"}
following_posts_user GET /users/:id/following_posts(.:format) {:action=>"following_posts", :controller=>"users"}
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"}
posts GET /posts(.:format) {:action=>"index", :controller=>"posts"}
POST /posts(.:format) {:action=>"create", :controller=>"posts"}
new_post GET /posts/new(.:format) {:action=>"new", :controller=>"posts"}
edit_post GET /posts/:id/edit(.:format) {:action=>"edit", :controller=>"posts"}
post GET /posts/:id(.:format) {:action=>"show", :controller=>"posts"}
PUT /posts/:id(.:format) {:action=>"update", :controller=>"posts"}
DELETE /posts/:id(.:format) {:action=>"destroy", :controller=>"posts"}
votes GET /votes(.:format) {:action=>"index", :controller=>"votes"}
POST /votes(.:format) {:action=>"create", :controller=>"votes"}
new_vote GET /votes/new(.:format) {:action=>"new", :controller=>"votes"}
edit_vote GET /votes/:id/edit(.:format) {:action=>"edit", :controller=>"votes"}
vote GET /votes/:id(.:format) {:action=>"show", :controller=>"votes"}
PUT /votes/:id(.:format) {:action=>"update", :controller=>"votes"}
DELETE /votes/:id(.:format) {:action=>"destroy", :controller=>"votes"}
comments GET /comments(.:format) {:action=>"index", :controller=>"comments"}
POST /comments(.:format) {:action=>"create", :controller=>"comments"}
new_comment GET /comments/new(.:format) {:action=>"new", :controller=>"comments"}
edit_comment GET /comments/:id/edit(.:format) {:action=>"edit", :controller=>"comments"}
comment GET /comments/:id(.:format) {:action=>"show", :controller=>"comments"}
PUT /comments/:id(.:format) {:action=>"update", :controller=>"comments"}
DELETE /comments/:id(.:format) {:action=>"destroy", :controller=>"comments"}
tags GET /tags(.:format) {:action=>"index", :controller=>"tags"}
POST /tags(.:format) {:action=>"create", :controller=>"tags"}
new_tag GET /tags/new(.:format) {:action=>"new", :controller=>"tags"}
edit_tag GET /tags/:id/edit(.:format) {:action=>"edit", :controller=>"tags"}
tag GET /tags/:id(.:format) {:action=>"show", :controller=>"tags"}
PUT /tags/:id(.:format) {:action=>"update", :controller=>"tags"}
DELETE /tags/:id(.:format) {:action=>"destroy", :controller=>"tags"}
events GET /events(.:format) {:action=>"index", :controller=>"events"}
POST /events(.:format) {:action=>"create", :controller=>"events"}
new_event GET /events/new(.:format) {:action=>"new", :controller=>"events"}
edit_event GET /events/:id/edit(.:format) {:action=>"edit", :controller=>"events"}
event GET /events/:id(.:format) {:action=>"show", :controller=>"events"}
PUT /events/:id(.:format) {:action=>"update", :controller=>"events"}
DELETE /events/:id(.:format) {:action=>"destroy", :controller=>"events"}
relationships POST /relationships(.:format) {:action=>"create", :controller=>"relationships"}
relationship DELETE /relationships/:id(.:format) {:action=>"destroy", :controller=>"relationships"}
root /(.:format) {:controller=>"pages", :action=>"subscribed"}
contact /contact(.:format) {:controller=>"pages", :action=>"contact"}
about /about(.:format) {:controller=>"pages", :action=>"about"}
live /live(.:format) {:controller=>"pages", :action=>"home"}
voted /voted(.:format) {:controller=>"pages", :action=>"highest_voted"}
signup /signup(.:format) {:controller=>"users", :action=>"new"}
Actually, ignore my previous answer and try this:
<li><%= link_to "Sign out", destroy_user_session_path, :method => :delete %></li>
The problem might be in your routes.rb file. You need to route user/signout appropriately and it needs to be above the route for your users, because routes work from the top down. If you post your routes file, I can help more.
Do you maybe have a resources :users above your devise_for :users?
I guess you can also try scoping the devise routes:
devise_scope :users do
get "sign_out", :to => "devise/sessions#destroy"
end

Rails Routes Namespaces and form_for

I have namespace in my routes.rb
namespace :businesses do
resources :registration
end
My controller is in a subdirectory businesses/registration_controller.
def new
#business = Business.new
end
In my view, I want to do this form_for #business do |f| ... but I am getting the following error:
No route matches {:controller=>"businesses", :action=>"create"}
Restarted the server and I'm also getting this:
undefined methodbusinesses_path' for #<#:0x10339bb20>`
Here are my rake routes:
home_index GET /home/index(.:format) {:action=>"index", :controller=>"home"}
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"}
user_password PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET /users/cancel(.:format) {:action=>"cancel", :controller=>"devise/registrations"}
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"}
user_registration PUT /users(.:format) {:action=>"update", :controller=>"devise/registrations"}
user_registration DELETE /users(.:format) {:action=>"destroy", :controller=>"devise/registrations"}
users GET /users(.:format) {:action=>"index", :controller=>"users"}
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"}
user PUT /users/:id(.:format) {:action=>"update", :controller=>"users"}
user DELETE /users/:id(.:format) {:action=>"destroy", :controller=>"users"}
full_tree_admin_categories GET /admin/categories/full_tree(.:format) {:action=>"full_tree", :controller=>"admin/categories"}
admin_categories GET /admin/categories(.:format) {:action=>"index", :controller=>"admin/categories"}
admin_categories POST /admin/categories(.:format) {:action=>"create", :controller=>"admin/categories"}
new_admin_category GET /admin/categories/new(.:format) {:action=>"new", :controller=>"admin/categories"}
edit_admin_category GET /admin/categories/:id/edit(.:format) {:action=>"edit", :controller=>"admin/categories"}
admin_category GET /admin/categories/:id(.:format) {:action=>"show", :controller=>"admin/categories"}
admin_category PUT /admin/categories/:id(.:format) {:action=>"update", :controller=>"admin/categories"}
admin_category DELETE /admin/categories/:id(.:format) {:action=>"destroy", :controller=>"admin/categories"}
businesses_registration_index GET /businesses/registration(.:format) {:action=>"index", :controller=>"businesses/registration"}
businesses_registration_index POST /businesses/registration(.:format) {:action=>"create", :controller=>"businesses/registration"}
new_businesses_registration GET /businesses/registration/new(.:format) {:action=>"new", :controller=>"businesses/registration"}
edit_businesses_registration GET /businesses/registration/:id/edit(.:format) {:action=>"edit", :controller=>"businesses/registration"}
businesses_registration GET /businesses/registration/:id(.:format) {:action=>"show", :controller=>"businesses/registration"}
businesses_registration PUT /businesses/registration/:id(.:format) {:action=>"update", :controller=>"businesses/registration"}
businesses_registration DELETE /businesses/registration/:id(.:format) {:action=>"destroy", :controller=>"businesses/registration"}
root /(.:format) {:action=>"index", :controller=>"home"}
If you have namespaced routes the best way is:
class Admin::BusinessesController < ApplicationController
def new
#business = Business.new
end
end
in routes.rb:
namespace :admin do
resources :businesses
end
In view:
form_for [:admin, #business] do |f|...
The Docs: http://guides.rubyonrails.org/form_helpers.html section 2.3.1 Dealing with Namespaces
Regarding your case:
In routes.rb everything is o'k. In the view you should write url explicitly because you have variable in controller other than controller name:
form_for #business, :url => business_registration_path do |f|...
I suppose that in businesses/registration_controller you have something like this:
class Businesses::RegistrationController < ApplicationController
def new
#business = Business.new
end
end
And one remark: I wouldn't create registration_controller for registering a new business. I think that keeping business related actions in business_controller is much clearer.
Actually, I think there is a better solution.
form_for [:admin, #business]
the issue with giving a url is that if you abstract the form out as a partial view, you'll need to deal with "create" and "update" situations. They points to different urls, and ends up with providing the #url in controller.

Resources