Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,7 @@ def referral_programs
end

def referral_program_create
@referral_program = Referral::Program.new(name: params[:name], creator: current_user)
@referral_program = Referral::Program.new(name: params[:name], redirect_to: params[:redirect_to], creator: current_user)

if @referral_program.save
flash[:success] = "Referral program created successfully."
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/referral/links_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def show
skip_authorization
end

redirect_to params[:return_to] || root_path
redirect_to @link.program.redirect_to.presence || root_path, allow_other_host: true
end

private
Expand Down
1 change: 1 addition & 0 deletions app/models/referral/program.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# login_header_text :string
# login_text_color :string
# name :string not null
# redirect_to :string
# created_at :datetime not null
# updated_at :datetime not null
# creator_id :bigint
Expand Down
4 changes: 3 additions & 1 deletion app/views/admin/referral_programs.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<div class="flex flex-col">
<h5 class="m-0 p-0"><%= program.name %></h5>
<small class="text-muted"><%= program.created_at.strftime("%Y-%m-%d") %> • Created by <%= program.creator.name %></small>
<small class="text-muted">Redirects to: <%= link_to(program.redirect_to.presence || root_url, program.redirect_to.presence || root_url) %></small>
</div>
<div class="flex flex-row gap-2 justify-between m-0">
<span class="m-0"><%= pluralize(program.users.size, "user") %><%= pluralize(program.new_users.size, "new user") %></span>
Expand Down Expand Up @@ -65,7 +66,8 @@
<legend>Create a referral program</legend>
<%= form.label :name, "Program name" %>
<%= form.text_field :name, placeholder: "Program Name", required: true, class: "w-100" %>
<br>
<%= form.label :redirect_to, "Redirect to (optional)" %>
<%= form.text_field :redirect_to, placeholder: "https://hcb.hackclub.com/", class: "w-100" %>
<%= form.submit "Create", class: "btn bg-success" %>
</fieldset>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddRedirectToToReferralPrograms < ActiveRecord::Migration[8.0]
def change
add_column :referral_programs, :redirect_to, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[8.0].define(version: 2025_12_05_035167) do
ActiveRecord::Schema[8.0].define(version: 2025_12_07_022849) do
create_schema "google_sheets"

# These are extensions that must be enabled in order to support this database
Expand Down Expand Up @@ -2010,6 +2010,7 @@
t.string "login_header_text"
t.string "login_text_color"
t.string "name", null: false
t.string "redirect_to"
t.datetime "updated_at", null: false
t.index ["creator_id"], name: "index_referral_programs_on_creator_id"
end
Expand Down