use route url helpers instead of hardcoding

This commit is contained in:
Zachary Chai 2017-02-17 16:05:59 -05:00
parent 16a1626130
commit 7873f640bc
3 changed files with 3 additions and 7 deletions

View File

@ -22,7 +22,7 @@ class SessionsController < ApplicationController
def create def create
@user = User.from_omniauth(request.env['omniauth.auth']) @user = User.from_omniauth(request.env['omniauth.auth'])
session[:user_id] = @user.id session[:user_id] = @user.id
redirect_to @user.room_url redirect_to meeting_room_url(resource: 'rooms', id: @user.encrypted_id)
rescue => e rescue => e
logger.error "Error authenticating via omniauth: #{e}" logger.error "Error authenticating via omniauth: #{e}"
redirect_to root_path redirect_to root_path

View File

@ -43,10 +43,6 @@ class User < ApplicationRecord
auth_hash['info']['email'] auth_hash['info']['email']
end end
def room_url
"#{Rails.configuration.relative_url_root}/rooms/#{encrypted_id}"
end
def set_encrypted_id def set_encrypted_id
self.encrypted_id = "#{username[0..1]}-#{Digest::SHA1.hexdigest(uid+provider)[0..7]}" self.encrypted_id = "#{username[0..1]}-#{Digest::SHA1.hexdigest(uid+provider)[0..7]}"
end end

View File

@ -17,9 +17,9 @@
<% if current_user %> <% if current_user %>
<div class="text-center"> <div class="text-center">
<% if @main_room %> <% if @main_room %>
<span><%= t('logged_in_description_html', link: link_to(current_user.name, current_user.room_url)) %></span> <span><%= t('logged_in_description_html', link: link_to(current_user.name, meeting_room_url(resource: 'rooms', id: current_user.encrypted_id))) %></span>
<% else %> <% else %>
<%= link_to(t('return_to_room'), current_user.room_url) %> <%= link_to(t('return_to_room'), meeting_room_url(resource: 'rooms', id: current_user.encrypted_id)) %>
<% end %> <% end %>
<div><%= link_to t('logout'), user_logout_url %></div> <div><%= link_to t('logout'), user_logout_url %></div>
</div> </div>