Here is my routes files:
Tubalr::Application.routes.draw do
devise_for :users
root :to => "application#index"
get "/player/:search_type/:search/:first_video" => "application#player"
get "/just/:artist_band.json" => "api#just"
get "/similar/:artist_band.json" => "api#similar"
get "/:username/favorites.json" => "api#userFavorites"
get "/just/:artist_band" => "application#index"
get "/similar/:artist_band" => "application#index"
get "/history" => "application#history"
get "/:username/favorites" => "favorites#init"
post "/check-favorites" => "favorites#check"
post "/favorites/add" => "favorites#add"
post "/favorites/remove" => "favorites#remove"
devise_scope :user do
get "/users/sign_out" => "devise/sessions#destroy"
end
end
The routes /history and the default /users/edit route for devise do not log the user out.
I'm not sure what other information to give, if theres something that would help debugging my problem, please let me know and I'll update the question.
The entire projects code can be found here: https://github.com/cjstewart88/Tubalr/tree/user_favorites
After digging around I finally ran into this:
https://github.com/plataformatec/devise/issues/913
It appears that the csrf token needs to be passed along with AJAX request, which my app is doing a good bit.
Related
I googled it but not got solution. I cant see change password form. (edit_user_password_path) it shows the message "you are already logged in" (Most probably flash[:error] and redirects to dashboard page. I am using rails 4 and device 3.5
User is my device model and I am using users controller as well (extend from ApplicationController) as I want to handle CRUD operations on User on my own. I am not using :registerable module of device.
my routes file looks like
devise_for :users, :path => 'u'
resources :users do
get 'manage_resource'
post 'manage_resource'
get 'profile'
end
Add the below snippet to your routes.rb file
devise_for :users, :skip => [:registrations]
as :user do
get 'users/edit' => 'devise/registrations#edit', :as => 'edit_user_registration'
put 'users' => 'devise/registrations#update', :as => 'user_registration' end
You should then be able to access edit_user_registration_path
Thanks to https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-edit-their-password
My goal is when user requests root (AND ONLY ROOT, other pages work fine) with something like:
http://domain.com/////
http://domain.com//////////////
http://domain.com//
app should 301 redirect user to one and only correct:
http://domain.com/
I'm using Webrick, rack-rewrite gem and planning to host it on Heroku.
Please remember that i'm new in Rails.
UPDATE ======
Rails: redirect all unknown routes to root_url
— this is totally different problem. They just redirect all unknown hosts to root. I have 404 working normally.
My problem is that any amount of slashes works as homepage and URL has all of those slashes. I'm doing it for SEO to get rid of duplicates of homepage. I want it to work like here: http://netpeak.ua (try "netpeak.ua////////", you will be redirected to "netpeak.ua").
UPDATE 2 - added content of routes.rb ======
Rails.application.routes.draw do
resources :questions
resources :feedbacks
devise_for :users
get '' => 'public#index'
get '/agency' => 'public#about'
get '/contact' => 'public#contact'
get '/uslugi' => 'services#index'
get '/portfolio' => 'projects#index'
get '/uslugi/:id' => 'services#show'
get '/portfolio/:id' => 'projects#show'
resources :articles, param: :id
resources :settings, as: 'home' #home so it doesn't go to another page
namespace :admin do
resources :articles, :users, :projects, :services, :feedbacks, :questions
get '' => 'projects#index'
get 'contact' => 'settings#contact'
get 'feedback' => 'settings#feedback'
get 'fininfo' => 'settings#fininfo'
get 'calls' => 'settings#calls'
get 'orders' => 'settings#orders'
get 'letters' => 'settings#letters'
get 'allquestions' => 'settings#allquestions'
get 'projectsettings' => 'settings#projectsettings'
get 'servicessettings' => 'settings#servicessettings'
get 'aboutsettings' => 'settings#aboutsettings'
get 'startpagesettings' => 'settings#startpagesettings'
patch 'contact' => 'settings#update'
patch 'feedback' => 'settings#update'
patch 'fininfo' => 'settings#update'
patch 'projectsettings' => 'settings#update'
patch 'servicessettings' => 'settings#update'
patch 'aboutsettings' => 'settings#update'
patch 'startpagesettings' => 'settings#update'
end
end
I am using Rails 4 and am trying to include the koudoku stripe gem. Here is my routes:
# Added by Koudoku.
mount Koudoku::Engine, at: 'koudoku'
scope module: 'koudoku' do
get 'pricing' => 'subscriptions#index', as: 'pricing'
end
resource :account
devise_for :users, :skip => [:sessions]
as :user do
get '/login' => 'devise/sessions#new', :as => :new_user_session
post '/login' => 'devise/sessions#create', :as => :user_session
get '/logout' => 'devise/sessions#destroy', :as => :destroy_user_session
end
get '/dashboard', to: 'dashboard#index'
get '/reports/generate', to: 'reports#generate'
authenticated :user do
root :to => 'dashboard#index', :as => :authenticated_root
end
root :to => redirect('/login')
And this is the error I am getting:
undefined local variable or method `root_url
I can access the other routes just fine, it is just trying to render the Application Helper methods (for instance, a custom app method I have defined, or routes methods) from the module routes... Does this make sense? How do I fix this?
Try adding "main_app." before your root path. For example:
main_app.root_path
Conditional logic in the routing layer kind of goes against the intent of the Rails MVC architecture. The route file should just map a web request to a controller, which then has conditional logic to determine what is displayed.
In this case it's a bit different since you want to redirect, but I personally would still put it in the controller. In other words send the root to dashboard#index, and then at the top of that controller (or in a before_filter) just do
redirect_to login_path unless current_user_authenticated?
(here I'm assuming you would have a named route for login, which would be good practice, as well as a current_user_authenticated? method to check whatever logic you want before the redirect. This would be a more Rails-y approach, whatever that's worth...)
Goal
When user submits the devise "edit registration" form, I want to redirect to users#show rather than the site's root.
Problem
Following Devise's instructions has not worked. I don't want to customize the Devise controller, so I'm left with two suggested modifications to routes.rb, either
devise_for :users do
get 'users', :to => 'users#show', :as => :user_root
end
or
match 'user_root' => 'users#show'
The first redirects to http://localhost:3000/users after submitting the edit form, the second redirects to http://localhost:3000/user_root. Both give the same error, "Couldn't find User without an ID".
My users#show page normally works in the app, so it's not an error with the controller method (or view, of course). It seems to be a routing error. I have "resources :users" in my routes.rb file, nothing else regarding users. If I need to give more information please let me know!
Question
Why isn't the user id being passed in the url?
Have you considered making the action a member action? this will ensure that the url format is controller//action. I don't know if you can even use the member thing in the devise route definition, but that's where I'd start.
devise_for :users do
member do
get 'users', :to => 'users#show', :as => :user_root
end
end
The member part doesn't work but if you take that out it is working for me. +1 to jaydel for close enough :P
devise_for :users do
get 'users', :to => 'users#show', :as => :user_root
end
Another thing that I tried which also worked was :
devise_scope :user do
get 'users' => 'users#show', :as => :user_root
end
I have a really simple app I've built using RoR but I'm stuck modifying my routes.
It's basically a site which lists user information - I need to change the url from:
mydomain.com/users/user-1
to
mydomain.com/user-1
Update..
I've managed to route the above request using:
match "/:id", :controller=>"users", :action=>"show"
But what I really need to do is change the route for all requests to /users/# to /
Although my route is working, all my links to show a user still point to:
/users/user-#
--- Update ---
The routing for /user-id is now working perfectly however, I'm struggling with the rest of the routing now.
I can now navigate to http://localhost/user-1
However, I basically need to remove the /user/ part completely. When I'm editing / updating a page, I end up with it going to:
/users/user-1/edit
All works fine but it then redirects to"
/users/user-1/
I really need both of these to redirect to
http://localhost/user-1/edit
Thanks
Bob
You want:
resources :users, :path => '/'
I believe get ":id" => "users#show" will be much the same except you only allow HTTP GET. Hope this works.
At the bottom of your routes
match "/:id", :to => "users#show"
There is some side effects so be ready
to rewrite your routes you should specify its name:
match "/:id", :to => "users#show", :as => :user
or, as #Whirlwin pointed, better to use just GET request as default
get "/:id", :to => "users#show", :as => :user
So now you can call:
user_path(#user)