I have the following routes in my 3.1.0.rc5 app
# config/routes.rb
devise_for :users
resources :users, only: :index
resource :user
THe idea here is that I use devise for session management, the 'users' resource just to generate the users_path for the index action and then most other user actions would be accessible via routes like
GET user_path -> show action
GET new_user_path -> new action
POST user_path -> create action
The user_path route helper doesn't seem to be generated though, whenever I try to use it in a view, I get a weird error when rails tries to render it.
For example, on the /user/new page, I have the following
<%= form_for #user, :url => user_path do |f| %>
# omitted form elements
<% end %>
When rails tries to render the page I get
ActionView::Template::Error (No route matches {:action=>"destroy", :controller=>"users"}):
7: </div>
8:
9: <div class="content_middle">
10: <%= form_for #user, :url => user_path do |f| %>
11: <fieldset>
12: <%= render partial: "form_errors" %>
13:
app/views/users/new.html.erb:10:in `_app_views_users_new_html_erb___1548382046039026466_2191201580'
What's up with that!?
Edit Here is the content of rake routes. It's pretty massive so I cut it down to just the user related 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"}
users GET /users(.:format) {:action=>"index", :controller=>"users"}
POST /users(.:format) {:action=>"create", :controller=>"users"}
user DELETE /users/:id(.:format) {:action=>"destroy", :controller=>"users"}
POST /user(.:format) {:action=>"create", :controller=>"users"}
new_user GET /user/new(.:format) {:action=>"new", :controller=>"users"}
edit_user GET /user/edit(.:format) {:action=>"edit", :controller=>"users"}
GET /user(.:format) {:action=>"show", :controller=>"users"}
PUT /user(.:format) {:action=>"update", :controller=>"users"}
It might make sense to have a Profile or CurrentUser controller in this situation. It would eliminate any routing conflicts you may be having with Devise, and also, it makes sense from a RESTful point of view as you're treating the current user as a distinct resource.
devise_for :user
resources :users, :only => :index
resource :profile
Related
I'm receiving the following error in my Rails app when I try to access a page that contains a form to create a post. I'm trying to implement a feature similar to Michael Hartl's Micropost feature in his sample app:
NoMethodError in Home#index
undefined method `posts_path' for #<#<Class:0xb5c70744>:0xb60013b8>
Here's the index view page that contains the code to insert the form:
<%= render 'shared/post_form' if user_signed_in? %>
_post_form.html.erb:
<%= form_for(#post) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<div class="field">
<%= f.text_area :content, placeholder: "Provide your network with a status update..." %>
</div>
<%= f.submit "Post", class: "btn btn-large btn-primary" %>
<% end %>
Here is the Home controller:
class HomeController < ApplicationController
before_filter :authenticate_user!
def index
#render :text => "Welcome #{current_user.email}!"
#users = User.all
#post = current_user.posts.build if signed_in?
end
end
I can really use some help in reviewing the code. I'm staring at it and I need someone else to review it for me. I'm new to Rails so please forgive me if I did not provide the necessary information.
Additional information: I'm using the Devise gem to handle user authentication.
Thanks!
EDIT: I added the wrong controller.
EDIT 2:
Routes.rb file:
AppName::Application.routes.draw do
#get "users/index"
#get "users/show"
authenticated :user do
root :to => 'home#index'
end
root :to => "home#index"
devise_for :users
resources :users do
member do
get :following, :followers, :posts
end
end
resources :works
resources :relationships, only: [:create, :destroy]
end
EDIT 3: Rake routes
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) 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
following_user GET /users/:id/following(.:format) users#following
followers_user GET /users/:id/followers(.:format) users#followers
posts_user GET /users/:id/posts(.:format) users#posts
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
works GET /works(.:format) works#index
POST /works(.:format) works#create
new_work GET /works/new(.:format) works#new
edit_work GET /works/:id/edit(.:format) works#edit
work GET /works/:id(.:format) works#show
PUT /works/:id(.:format) works#update
DELETE /works/:id(.:format) works#destroy
relationships POST /relationships(.:format) relationships#create
relationship DELETE /relationships/:id(.:format) relationships#destroy
You need to add resources :posts in your routes.rb file in order for Rails to automatically create the posts_path helper for you.
Adding resources :posts will generate the proper RESTful routes for you to create, delete, update, and fetch posts. Take a look at the Ruby on Rails Guide for routing, specifically this section here on routing and RESTful routes.
OK so this is my first question posted to stackoverflow. I'm pretty new to coding, been learning Ruby on Rails for the past 3 months. There could be a few things wrong with my code but here it goes.
Basically I'm trying to get a User to Post. I'm using Devise for registration, and all of that works. But when I create a link to "Create Post" in my Header View, it tells me I don't have a route matching => even though I think it exists. I'm missing something small I believe but in all the debugging I've done to try and get it right, I think I might have messed something else up along the way. Below is attached my code for the routes.rb, my post_controller file, and my layout view file. Sorry about all the rambling, I couldn't be very concise. Does anyone see anything wrong? Let me know if you need to see other code
_header.html.erb
<% if user_signed_in? %>
Signed in as <%= current_user.username %>. Not you?
<%= link_to "Logout", destroy_user_session_path, :method => :delete, %>
<%= link_to "Create Post", new_user_post_path %>
<%= link_to "Search", posts_index_path %>
<%= link_to "Show All", posts_show_path %>
routes.rb
#devise_for :users
devise_for :users do get '/users/sign_out' => 'devise/sessions#destroy' end
match '/users/:user_id/posts/new', :to => 'posts#new'
resources :users do
resources :posts, :only => [:new, :create, :show, :index, :destroy]
end
match '/contact', :to => 'pages#contact'
match '/about', :to => 'pages#about'
match '/help', :to => 'pages#help'
match '/safety', :to => 'pages#safety'
match '/privacy', :to => 'pages#privacy'
get 'posts/index'
get 'posts/show'
get 'posts/post'
match 'posts/search', :to => 'posts#search'
root :to => 'pages#home'
posts_controller
def create
if signed_in?
#user = current_user.posts.build(params[:user][:post])
if #user.save
flash[:success] = "Thanks for creating your post! " +
redirect_to new_user_post_path(#post)
else
render 'new'
def new
#title = "Create Post"
#post = Post.new
end
rake routes
users_sign_out GET /users/sign_out(.:format) {:controller=>"devise/sessions", :action=>"destroy"}
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"}
/users/:user_id/posts/new(.:format) {:controller=>"posts", :action=>"new"}
user_posts GET /users/:user_id/posts(.:format) {:action=>"index", :controller=>"posts"}
POST /users/:user_id/posts(.:format) {:action=>"create", :controller=>"posts"}
new_user_post GET /users/:user_id/posts/new(.:format) {:action=>"new", :controller=>"posts"}
user_post GET /users/:user_id/posts/:id(.:format) {:action=>"show", :controller=>"posts"}
DELETE /users/:user_id/posts/:id(.:format) {:action=>"destroy", :controller=>"posts"}
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"}
contact /contact(.:format) {:controller=>"pages", :action=>"contact"}
about /about(.:format) {:controller=>"pages", :action=>"about"}
help /help(.:format) {:controller=>"pages", :action=>"help"}
safety /safety(.:format) {:controller=>"pages", :action=>"safety"}
privacy /privacy(.:format) {:controller=>"pages", :action=>"privacy"}
posts_index GET /posts/index(.:format) {:controller=>"posts", :action=>"index"}
posts_show GET /posts/show(.:format) {:controller=>"posts", :action=>"show"}
posts_post GET /posts/post(.:format) {:controller=>"posts", :action=>"post"}
posts_search /posts/search(.:format) {:controller=>"posts", :action=>"search"}
root /(.:format) {:controller=>"pages", :action=>"home"}
Try typing rake routes in the console and check if the route you are looking for exists. Note that the order also matters.
It should have been
<%= link_to "Create Post", new_user_post_path(current_user) %>
I think its because of the argument !
In your routes file it seems you are passing :user_id also.
In your link try passing that id.
Hope it helps...
<%= link_to "create Post", new_user_post_path(current_user.id) %>
Also I would suggest try renaming the path and use it.
I know its not proper way but still.
I had faced a similar problem and solved by doing this !!;)
Hope it helps !
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
So after pulling my hair out for an hour, I decided to post this here. I get this error:
NoMethodError in Articles#show
Showing /home/leon/sites/VIS/app/views/articles/_article.html.erb where line #3 raised:
undefined method `user_path' for #<#<Class:0x7fdd81fe1eb8>:0x7fdd81fdfdc0>
Extracted source (around line #3):
1: <div id="left-column">
2: <p class="label-b">Author<br>
3: <%= link_to "#{#article.user.penname}'s profile", user_path(article.user) %>
user_path(article.user) %>
When I try to link to the article's authoring user. My routes file:
resources :tags
get "admin/index"
get "admin/show"
get "articles/contact"
get "articles/about"
resources :roles
devise_for :users, :controllers => { :registrations => "users/registrations" }
resources :articles do
resources :comments
end
I do have a belongs_to :user in my article model file and a has_many :articles in my user model file. I'm using this link to link to the author's profile within the article.
Please help! I'm using can can for my permission management and devise for my authentication, but its throwing the error within the show action of the article so I didn't post that code. Let me know if I should. Thanks!
#Jacob
I get the same error:
NoMethodError in Articles#show
Showing /home/leon/sites/VIS/app/views/articles/_article.html.erb where line #3 raised:
undefined method `user_path' for #<#:0x7fdd82217a98>
Extracted source (around line #3):
1:
2: Author
3: <%= link_to "#{#article.user.penname}'s profile", article.user %>
4: Previous Versions
5: Version 7
6: <%= image_tag "add-to-favorites.png", :class => "favorites-button" %>
The relevant part of my routes:
{:action=>"destroy", :controller=>"roles"}
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"}
user_registration POST /users(.:format) {:action=>"create", :controller=>"users/registrations"}
new_user_registration GET /users/sign_up(.:format) {:action=>"new", :controller=>"users/registrations"}
edit_user_registration GET /users/edit(.:format) {:action=>"edit", :controller=>"users/registrations"}
user_registration PUT /users(.:format) {:action=>"update", :controller=>"users/registrations"}
user_registration DELETE /users(.:format) {:action=>"destroy", :controller=>"users/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"}
user_confirmation GET /users/confirmation(.:format) {:action=>"show", :controller=>"devise/confirmations"}
Aha! It doesn't have a route for user#show, but i'm not sure why as I have:
class UsersController < ApplicationController
...
def show
respond_to do |format|
format.json { render :json => #user }
format.xml { render :xml => #user }
format.html
end
rescue ActiveRecord::RecordNotFound
respond_to_not_found(:json, :xml, :html)
end
in my app/controllers folder. Do I need to move my users controller into app/controllers/devise and overload it with devise instead of application controller?
You can do:
<%= link_to "#{#article.user.penname}'s profile", article.user %>
And Rails will automatically determine the route.
As seen here:
http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to
Update
Yes, you are going to have to inherit from the DeviseController rather than the ApplicationController. From here you can add your own custom actions, such as show(which is what you doing now).
Look at: https://github.com/plataformatec/devise
and search for: Configuring controllers
Try article.user instead of user_path(article.user). If that doesn't work, can you post the output from rake routes?
I figured it out. After playing around with the routes for a while and reading the rails documentation, I added this line to my routes file:
devise_for :users, :controllers => { :registrations => "users/registrations" }
resources :users, :only => [:index, :show] <== THIS LINE
below my devise_for routes. This allows me to display the user profiles without having to worry about the edit update etc. roles that devise provides for. Thanks for the answers anyway guys, I appreciate it!
Shouldn't it just be: #article.user instead of article.user ??
<%= link_to "#{#article.user.penname}'s profile", #article.user %>
Why would you use an instance variable for the user penname and a local variable for the user object? I think that's your problem.
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.