From 977e1c5cec4e14d1ca6eab8a4f70b42b6909e61b Mon Sep 17 00:00:00 2001 From: Carol Nichols Date: Fri, 17 Feb 2012 21:43:53 -0500 Subject: [PATCH] Naming some routes; making all the redirects use route helpers consistently --- app/controllers/auth_controller.rb | 6 ++-- app/controllers/users_controller.rb | 44 ++++++++++++++--------------- config/routes.rb | 10 +++---- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/app/controllers/auth_controller.rb b/app/controllers/auth_controller.rb index 689ba7b5..1b2b63e1 100644 --- a/app/controllers/auth_controller.rb +++ b/app/controllers/auth_controller.rb @@ -18,7 +18,8 @@ def auth unless @auth = Authorization.find_from_hash(auth) if logged_in? Authorization.create_from_hash!(auth, root_url, current_user) - redirect_to [:edit, current_user] and return + redirect_to edit_user_path(current_user) + return else # This situation here really sucks. I'd like to do something better, @@ -44,7 +45,6 @@ def auth end redirect_to new_user_path - return end end @@ -90,6 +90,6 @@ def destroy session[:user_id] = user.id end - redirect_to [:edit, user] + redirect_to edit_user_path(user) end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 87b6ad31..050d9497 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -99,15 +99,11 @@ def create_from_email end end - # This is pretty much the same thing as /feeds/your_feed_id, but we + # This is pretty much the same thing as /feeds/your_feed_id.atom, but we # wanted to have a really nice URL for it, and not just the ugly one. - # Since it's only two lines, we don't bother to do a redirect, and - # it's arguably better to display them as two different resources. - # Whatevs. - # Except we ARE doing a redirect??? /me shakes fist at steve def feed if @user - redirect_to "/feeds/#{@user.feed.id}.atom" + redirect_to feed_path(@user.feed, :format => :atom) else render :file => "#{Rails.root}/public/404.html", :status => 404 end @@ -118,8 +114,10 @@ def feed def following if @user.nil? render :file => "#{Rails.root}/public/404.html", :status => 404 - elsif @user.username != params[:id] # case difference - redirect_to "/users/#{@user.username}/following" + # If the username's case entered in the URL is different than the case + # specified by that user, redirect to the case that the user prefers + elsif @user.username != params[:id] + redirect_to following_path(@user.username) else set_params_page @@ -149,8 +147,10 @@ def following def followers if @user.nil? render :file => "#{Rails.root}/public/404.html", :status => 404 - elsif @user.username != params[:id] # case difference - redirect_to "/users/#{@user.username}/followers" + # If the username's case entered in the URL is different than the case + # specified by that user, redirect to the case that the user prefers + elsif @user.username != params[:id] + redirect_to followers_path(@user.username) else set_params_page @@ -183,17 +183,17 @@ def confirm_email user = User.first(:perishable_token => params[:token]) if user.nil? flash[:notice] = "Can't find User Account for this link." - redirect_to "/" + redirect_to root_path elsif user.token_expired? flash[:notice] = "Your link is no longer valid, please request a new one." - redirect_to "/" + redirect_to root_path else user.email_confirmed = true user.reset_perishable_token # Register a session for the user session[:user_id] = user.id flash[:notice] = "Email successfully confirmed." - redirect_to "/" + redirect_to root_path end end @@ -217,7 +217,7 @@ def forgot_password_create Notifier.send_forgot_password_notification(user.email, user.create_token) # Redirect to try to avoid repost issues session[:fp_email] = user.email - redirect_to '/forgot_password_confirm' + redirect_to forgot_password_confirm_path end end @@ -230,7 +230,7 @@ def forgot_password_confirm def reset_password_new if not logged_in? - redirect_to "/forgot_password" + redirect_to forgot_password_path else render "login/password_reset" end @@ -254,20 +254,20 @@ def reset_password_create if params[:password].size == 0 flash[:notice] = "Password must be present" - redirect_to "/reset_password/#{params[:token]}" + redirect_to reset_password_path(params[:token]) return end if params[:password] != params[:password_confirm] flash[:notice] = "Passwords do not match" - redirect_to "/reset_password/#{params[:token]}" + redirect_to reset_password_path(params[:token]) return end if user.email.nil? if params[:email].empty? flash[:notice] = "Email must be provided" - redirect_to "/reset_password/#{params[:token]}" + redirect_to reset_password_path(params[:token]) return else user.email = params[:email] @@ -277,9 +277,9 @@ def reset_password_create user.password = params[:password] user.save flash[:notice] = "Password successfully set" - redirect_to "/" + redirect_to root_path else - redirect_to "/forgot_password" + redirect_to forgot_password_path end end @@ -290,10 +290,10 @@ def reset_password_with_token user = User.first(:perishable_token => params[:token]) if user.nil? || user.token_expired? flash[:notice] = "Your link is no longer valid, please request a new one." - redirect_to "/forgot_password" + redirect_to forgot_password_path else @token = params[:token] - @user = user + @user = user render "login/password_reset" end end diff --git a/config/routes.rb b/config/routes.rb index a111b972..ffd4d135 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,15 +26,15 @@ match "users/:id/feed", :to => "users#feed", :as => "user_feed", :constraints => { :id => /[^\/]+/ } # other new route? - match 'users/:id/followers', :to => "users#followers", :constraints => { :id => /[^\/]+/ } - match 'users/:id/following', :to => "users#following", :constraints => { :id => /[^\/]+/ } + match 'users/:id/followers', :to => "users#followers", :constraints => { :id => /[^\/]+/ }, :as => "followers" + match 'users/:id/following', :to => "users#following", :constraints => { :id => /[^\/]+/ }, :as => "following" match 'confirm_email/:token', :to => "users#confirm_email" - match 'forgot_password', :to => "users#forgot_password_new", :via => :get + match 'forgot_password', :to => "users#forgot_password_new", :via => :get, :as => "forgot_password" match 'forgot_password', :to => "users#forgot_password_create", :via => :post - match 'forgot_password_confirm', :to => "users#forgot_password_confirm", :via => :get + match 'forgot_password_confirm', :to => "users#forgot_password_confirm", :via => :get, :as => "forgot_password_confirm" match 'reset_password', :to => "users#reset_password_new", :via => :get match 'reset_password', :to => "users#reset_password_create", :via => :post - match 'reset_password/:token', :to => "users#reset_password_with_token", :via => :get + match 'reset_password/:token', :to => "users#reset_password_with_token", :via => :get, :as => "reset_password" # Updates resources :updates, :only => [:index, :show, :create, :destroy]