I've made authorization following this tutorial: https://www.railstutorial.org/book/sign_in_out#cha-sign_in_sign_out but now I want to add subdomains to my application.
I've added this to my routes.rb:
match '/' => 'students/board', :constraints => { :subdomain => 'student' }, via: 'get'
If I want to redirect user after sign in to his subdomain like this:
redirect_to :subdomain => 'student', :path => '/'
I'm getting this error:
No route matches [GET] "/sessions"
If I redirect user without a subdomain he is normally redirected. I don't understand why it's trying to get 'sessions' path. I would be grateful for some suggestions. I didn't find anything online which is related to login sessions and subdomains.
Thanks!
There might be something in your code you aren't showing us redirecting you to the sessions path.
Have you tried naming the path then redirecting there?
routes.rb:
get '/' => 'students/board', :constraints => { :subdomain => 'student' }, as: 'student_login'
then use:
redirect_to student_login_path
Related
I'm dealing with an application that's using Rails 2.3.18 and I'm wondering if it's possible to route multiple url's to the same action without creating a new map.
map.home '/', :controller => 'pages', :action=>'home', :path=>'home'
Is it possible to route to '/', as well as '/home' in this mapping?
I've been having a look through the routing documentation and I can't seem to find anything that allows you to do something like this, is it possible?
you can try this:
map.home '/', :controller => 'pages', :action => 'home'
map.home '/home', :controller => 'pages', :action => 'home'
Yes, you can do these routes as :
root "page#home" // this work as root for '/' path
&
get "/home" => "page#home"
This is the solution but if you want to do it with seperate routes without root_path then :
get "/" => "page#home"
get "/home" => "page#home"
I'm looking for a way to use subdomains as a permalink in rails.
For example:
Instead of http://domain.com/user2 pointing to user2's profile.
I would like http://user2.domain.com to point to user2's profile.
Anyone know of a solution to this that will work on heroku?
Routes:
get '/' => 'home#index', :constraints => { :subdomain => 'www' }
get '/' => 'users#show', :constraints => { :subdomain => /.+/ }
Users Controller:
#user = User.find_by_permalink(request.subdomain)
I'd like so overwrite my root :to => redirect("/projects") route if the subdomain is equal to "www" or is just "". This means if the subdomain is "www" or "" the app should use my website#index controller/action.
At the moment I got this setup:
class Subdomain
def self.match(r)
r.subdomain == "www" || r.subdomain == ""
end
end
.....
# website
scope :constraints => lambda { |request| Subdomain.match(request) } do
get '/' => 'website#index'
get "/help" => "website#help", as: "help"
get "/about" => "website#about", as: "about"
get "/signup" => "website#signup", as: "signup"
# post "/signup" => "website#signup_account"
end
root :to => redirect("/projects")
If I access www.satisfy.dev/help or satisfy.dev/help everything works fine. If I access www.satisfy.dev/ or satisfy.dev/ the root_path (/projects) is in use. I thought the get '/' => 'website#index' should be more important than the root_path since it's above the root_path.
Hope somebody has a hint for me!
I tried treating the routes as "get" requests and had more success.
See here:
Multiple 'root to' routes in rails 4.0
I have a URL I want to be able to redirect to.
Something similar to:
"http://localhost:3000/username/admin/page".
I have a match in routes.rb as:
match ':account/admin/:page' => "admin#index"
I have redirect code:
redirect_to :controller => account.username, :action=>"admin", :page=>"index"
This, however comes up with a routing error:
No route matches {:action=>"admin", :controller=>"sdunn", :page=>"index"}
I know what I have done is wrong, but how can I fix this?
Many thanks.
Route is expecting 2 parameters, first one is :account, second is :page, i think you are only passing :page. I would add :as => 'some_name' to your route and then use _path :
routes.rb
match ':account/admin/:page' => "admin#index", :as => 'my_route'
controller:
redirect_to my_route_path(#user, #page)
my_route_path could be something different depending on your exact route file, so use
rake routes | grep my_route
to see exact name, then add _path to the end.
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.