Okay, these two related questions are in reference to Railscast #21:
I'm having some trouble with routes. Two issues:
1) The routes in the tutorial seem to be relative to the root of the application; I want them to be relative to the root of the model. So
"http://example.com/login
" I need to be "http://example.com/model/login
" (and vice versa for logout).
I'm using permalinks to refer to my records, and I don't know how to specify an override, because every time I try to use "http://example.com/model/login
" I get an error that says it can't find the record "login". How can I override this for login/logout?
2) Going to a custom route for me doesn't seem to keep the custom route in my address bar. So going to "http://example.com/login
" gets me to the right page, but the browser now says "http://example.com/session/new
" in the address bar. In the tutorial this doesn't happen: the app serves the correct page and keeps the custom route in the address bar. How can I get this to happen for me?
## Sessions Controller
class SessionController < ApplicationController
def create
session[:password] = params[:password]
flash[:notice] = "Successfully Logged In"
redirect_to :controller => 'brokers', :action => 'index'
end
def destroy
reset_session
flash[:notice] = "Successfully Logged Out"
redirect_to login_path
end
end
## Routes
ActionController::Routing::Routes.draw do |map|
map.resources :brokers, :session
map.login 'login', :controller => 'session', :action => 'create'
map.logout 'logout', :controller => 'session', :action => 'destroy'
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end