HAML link not working - ruby-on-rails

I made this HAML link:
= link_to "Create Profile", signup_path
I was thinking it should work since this url works:
http://m.cmply.local:8800/signup
But instead I get this error:
undefined local variable or method `signup_path' for #<#<Class:0x129a08190>:0x129a027e0>
Here is my routes.rb snippet
scope :module => :mobile, :as => :mobile do
constraints(:subdomain => /m/) do
devise_for :users, :path => "", :path_names =>
{ :sign_in => "login", :sign_out => "logout",
:sign_up => "signup" },
:controllers => {:sessions => "mobile/sessions"}
resources :home
resources :disclosures # Will have new, get, look up a disclosure
end
end
and here is the rake routes snippet
{:action=>"create", :controller=>"registrations"}
new_user_registration GET /signup(.:format)
Any idea why this might happen?
Thanks!

Change signup_path to new_user_registration_path

This is happening because rails does not know what "signup_path" is. I would recommend you run bundle exec rake routes and be sure that signup_path is actually in those routes. I can tell by looking at your routes.rb file that you're not going to have the signup_path route.
The route you are looking for is going to be something more like users_signup_path, because devise likes to wrap its routes in namespaces like that.

Try placing app_main.signup_path. It seems that is getting called on a different engine.
I've ran into this problem before.
And follow the directions of others such as to check your routes.

Related

Change the default Devise GET user path

I want to change the default path of some user (in this case with id = 1) information from:
domain.com/user.1
to
domain.com/user/1
I already use devise_for on my route.rb, is there some special command to do what I need with this?
this is my route.rb
devise_for :users,
:path => '',
:path_names => {
:sign_in => 'login',
:sign_out => 'logout',
:sign_up => 'register'
},
:controllers => { registrations: 'registrations' }
First, domain.com/user.1 doesn't look like a real route to me. Are you sure you're not calling users_path(id) when you intend to call user_path(id)?
Also, a user/:id route doesn't look like it has anything to do with Devise, which is concerned with authentication/authorization. It looks more like a show resource method that would go in UsersController#show.
In any case, the following route should give you the /user/:id route which maps to UsersController#show
resources :user
which would create the following route helper method:
user_path(id)

ruby on rails button_to not activating the delete method

Hi im following the agile web development ebook and i cant seem to activate the logout action
here are the revelant parts (TAB key not working could not format to code)
rake routes
logout DELETE /logout(.:format) sessions#destroy
from the route file
controller :sessions do
get 'login' => :new
post 'login' => :create
delete 'logout' => :destroy
end
my controller
def destroy
session[:user_id] = user.id
redirect_to store_url , notice: "Logged out"
end
and my view (relevant part)
<%= button_to 'Logout', logout_path, method: :delete %>
the error message is
No route matches [GET] "/logout"
i know it should use delete method but nothing i do seems to help
You may need to add a match in your routes. Sorry that I don't have the book with me to refer to.
Put this above your controller :sessions ...
match 'logout' => 'sessions#destroy', :as => :logout
If you didn't put the above line, your logout path should be sessions_logout_path, not logout_path.
Reference:
http://guides.rubyonrails.org/routing.html#naming-routes
match '/logout' => 'sessions#destroy', :via => :delete
or
controller :sessions do
member do
delete :destroy, :as => :logout
end
end

Devise routing error not understand

I have this route file
Qitch::Application.routes.draw do
devise_for :users, :controllers => {
:omniauth_callbacks => "users/omniauth_callbacks",
:registrations => "users/registrations",
:sessions => "users/sessions",
:passwords => "users/passwords"
}
devise_for :users
as :user do
get '/sign_up', :to => "users/registrations#new"
get "sign_out", :to => "users/sessions#destroy"
end
root :to => 'welcome#index'
end
when i click on this link in application layout
Sign-up Now, It's fast and free
i have this error
Routing Error
No route matches {:controller=>"users/welcome"}
Try running rake routes for more information on available routes.
I don't understand why this occur
Any help
Thanks
1.) as the Routing Error promts, try to run rake routes which will show you all defined routes, from the output you can see if you defined something not as wanted
2.) as stated in devise custom routes try something like:
get "/sign_up" => "devise/registrations#new"
3.) use the paths in your view: generating paths and urls from code
<%= link_to "Login", signup_user_path %>

How do I map the `/users/sign_up` path to `/users/new`?

I am using Ruby on Rails 3.2.2 and I would like to "use" the /users/sign_up PATH instead of /users/new in order to register new users to my application.
How can I make that "a là Ruby on Rails Way"?
Note: at this time I am using the following code in the routes.rb file but I think it isn't the best way to accomplish that I am looking for:
resources :users, :except => [:new] do
collection do
get 'sign_up'
end
end
What would you advise?
This should work:
resources :users, :path_names => {:new => 'sign_up'}
Its in the docs here
You can do the following:
match '/users/sign_up' => 'users#new', :as => :signup
and make links with the signup_path helper method

Is there an equivalent of "after_sign_in_path_for" for user edit/commit?

Running Rails 3.2.1 with devise-2.0.4.gem.
Is there an equivalent redirect configuration for user/commit similar to "after_sign_in_path_for"? In production, I have to use HTTPS so the URL for "Edit User" is https://www.xyz.com/users/edit. When I click "Update", the correct update takes place but then Devise redirects to "http://www.xyz.com/users/edit" which results in error loading page since HTTP is not supported in production.
I had a similar issue with sign in/out (http://groups.google.com/group/plataformatec-devise/browse_thread/thread/5fafb2a8c90f1d43) which I solved by defining after_sign_in_path_for. But I don't see such similar config for user edit/commit.
Then I tried to force HTTPS in routes.rb:
devise_scope :user do
get "users/edit", :to => "users/registrations#edit", :as => :edit_user, :protocol => "https"
put "users/commit", :controller => "users/registrations", :action => 'commit', :as => :commit_user, :protocol => "https"
end
And see this in rake routes:
edit_user GET /users/edit(.:format) users/ registrations#edit {:protocol=>"https"}
commit_user PUT /users/commit(.:format) users/registrations#commit {:protocol=>"https"}
But Devise still routes to HTTP after the update action.
Looking at registrations_controller.rb, I see several instances of
redirect_to edit_user_path
So as a work around, I change it to
redirect_to https://www.xyz.com/user/edit
And that is working. But I'm not sure if this is the correct approach.

Resources