Skip to content

Commit c9cd7b2

Browse files
committed
Include personal link formatting instructions in profile form
1 parent e541099 commit c9cd7b2

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

app/models/participant.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Participant < ActiveRecord::Base
88

99
validates_presence_of :name
1010
validates_uniqueness_of :email, :case_sensitive => false, :allow_blank => true
11+
validate :bio_does_not_include_example_links
1112

1213
# used for formtastic form to allow sending a field related to a separate model
1314
attr_accessor :code_of_conduct_agreement
@@ -93,6 +94,12 @@ def deliver_email_confirmation_instructions!
9394
reset_perishable_token!
9495
Notifier.participant_email_confirmation(self).deliver_now!
9596
end
96-
end
9797

98+
private
9899

100+
def bio_does_not_include_example_links
101+
if bio&.include?("example.com")
102+
errors.add(:bio, "please remove sample links to “example.com”")
103+
end
104+
end
105+
end

app/views/participants/edit.html.erb

+17-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,23 @@
66
<%= f.inputs do %>
77
<%= f.input :name, :label => 'Your name', :hint => "Please use your real name. This will be used in our printed materials." %>
88
<%= f.input :email, :label => 'Your email', :hint => "Please use a real email address. We need this to contact you about your presentation." %>
9-
<%= f.input :bio, :hint => 'You can use <a href="http://daringfireball.net/projects/markdown/syntax">Markdown</a> syntax here. Examples: <strong>**bold**</strong>, <em>*italic*</em>, [link](http://example.com)'.html_safe %>
9+
<%= f.input :bio %>
10+
<p class="inline-hints">
11+
You can use <a href="http://daringfireball.net/projects/markdown/syntax">Markdown</a> syntax here.
12+
Examples: <code>**bold**</code> &nbsp; <code>_italic_</code> &nbsp; <code>[link](http://example.com)</code>
13+
</p>
14+
15+
<p class="inline-hints">
16+
Add links to your personal sites and socials using the following format at the end of your bio:
17+
</p>
18+
<pre>
19+
**Links:**
20+
21+
- [Personal site](https://myawesomesite.example.com)
22+
- [AwesomeNet](https://example.com/myusername)
23+
- [FriendTown](https://example.com/myusername)
24+
</pre>
25+
1026
<%=
1127
f.input :code_of_conduct_agreement,
1228
as: :boolean,

spec/models/participant_spec.rb

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
require 'spec_helper'
22

33
describe Participant do
4+
describe "validation" do
5+
subject { create(:luke) }
6+
7+
it { should validate_presence_of :name }
8+
9+
it "should flag example.com in bio text" do
10+
subject.bio = "blah blah https//example.com/foo blah"
11+
subject.save
12+
assert !subject.valid?
13+
assert !subject.errors[:bio].empty?
14+
end
15+
end
16+
417
describe "timeslot restrictions" do
518
let(:event) { create(:event) }
619
let!(:time1) { create(:timeslot_1, event: event) }

0 commit comments

Comments
 (0)