pass around root_url from view/controller into model when needed

This commit is contained in:
joshua stein 2012-07-01 15:06:36 -05:00
parent d85aed9475
commit 282f505cf2
10 changed files with 18 additions and 17 deletions

View file

@ -7,6 +7,7 @@ class InvitationsController < ApplicationController
i.email = params[:email]
i.memo = params[:memo]
if i.save
i.send_email(root_url)
flash[:success] = "Successfully e-mailed invitation to " <<
params[:email]
else

View file

@ -39,7 +39,7 @@ class LoginController < ApplicationController
return forgot_password
end
@found_user.initiate_password_reset_for_ip(request.remote_ip)
@found_user.initiate_password_reset_for_ip(root_url, request.remote_ip)
flash.now[:success] = "Password reset instructions have been e-mailed " <<
"to you."

View file

@ -1,7 +1,8 @@
class InvitationMailer < ActionMailer::Base
default from: "nobody@lobste.rs"
def invitation(invitation)
def invitation(root_url, invitation)
@root_url = root_url
@invitation = invitation
mail(to: invitation.email, from: "Lobsters Invitation <nobody@lobste.rs>",

View file

@ -1,7 +1,8 @@
class PasswordReset < ActionMailer::Base
default from: "nobody@lobste.rs"
def password_reset_link(user, ip)
def password_reset_link(root_url, user, ip)
@root_url = root_url
@user = user
@ip = ip

View file

@ -8,7 +8,6 @@ class Invitation < ActiveRecord::Base
end
before_create :create_code
after_create :send_email
def create_code
(1...10).each do |tries|
@ -22,7 +21,7 @@ class Invitation < ActiveRecord::Base
end
end
def send_email
InvitationMailer.invitation(self).deliver
def send_email(root_url)
InvitationMailer.invitation(root_url, self).deliver
end
end

View file

@ -84,9 +84,8 @@ class Story < ActiveRecord::Base
self.tags_to_add = []
end
def comments_url
Rails.application.routes.url_helpers.root_url +
"s/#{self.short_id}/#{self.title_as_url}"
def comments_url(root_url = "/")
root_url + "s/#{self.short_id}/#{self.title_as_url}"
end
@_comment_count = nil
@ -179,8 +178,8 @@ class Story < ActiveRecord::Base
u
end
def url_or_comments_url
self.url.blank? ? self.comments_url : self.url
def url_or_comments_url(root_url = "/")
self.url.blank? ? self.comments_url(root_url) : self.url
end
def is_editable_by_user?(user)

View file

@ -40,11 +40,11 @@ class User < ActiveRecord::Base
Keystore.value_for("user:#{self.id}:comments_posted").to_i
end
def initiate_password_reset_for_ip(ip)
def initiate_password_reset_for_ip(root_url, ip)
self.password_reset_token = Utils.random_str(45)
self.save!
PasswordReset.password_reset_link(self, ip).deliver
PasswordReset.password_reset_link(root_url, self, ip).deliver
end
def linkified_about

View file

@ -9,8 +9,8 @@
<% @stories.each do |story| %>
<item>
<title><%= raw coder.encode(story.title, :decimal) %></title>
<link><%= story.url_or_comments_url %></link>
<guid><%= story.comments_url %></guid>
<link><%= story.url_or_comments_url(root_url) %></link>
<guid><%= story.comments_url(root_url) %></guid>
<author><%= story.user.username %></author>
<pubDate><%= story.created_at.rfc2822 %></pubDate>
<comments><%= story.comments_url %></comments>

View file

@ -6,4 +6,4 @@ The user <%= @invitation.user.username %> has invited you to the website Lobster
To create an account, visit the URL below:
<%= root_url %>invitations/<%= @invitation.code %>
<%= @root_url %>invitations/<%= @invitation.code %>

View file

@ -4,4 +4,4 @@ Someone at <%= @ip %> requested to reset your account password
on lobste.rs. If you submitted this request, visit the link below to
set a new password. If not, you can disregard this e-mail.
<%= root_url %>login/set_new_password?token=<%= @user.password_reset_token %>
<%= @root_url %>login/set_new_password?token=<%= @user.password_reset_token %>