Skip to content

Commit 51b2fd9

Browse files
committed
bookmark controllers use the bookmark model validator to validate link
So the bookmark model is the only leader the validation of the link. Thus the protocol validation is moved to the model too.
1 parent 00c0b44 commit 51b2fd9

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

app/controllers/bookmarks_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def create
3737
@bookmark.node = Node.new(user_id: current_user.id, cc_licensed: false)
3838
@bookmark.node.preview_tags = params[:tags]
3939
@bookmark.valid?
40-
flash.now[:alert] = "Votre lien semble invalide. Le confimez‑vous ?" unless @bookmark.link =~ /\A#{URI::regexp(['http', 'https'])}\z/
40+
flash.now[:alert] = "Votre lien est invalide, veuillez le corriger." unless @bookmark.errors[:link].empty?
4141
render :new
4242
end
4343
end

app/models/bookmark.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Bookmark < Content
2626
validates :title, presence: { message: "Le titre est obligatoire" },
2727
length: { maximum: 100, message: "Le titre est trop long" }
2828
validates :link, presence: { message: "Vous ne pouvez pas poster un lien vide" },
29-
uri: { message: "Le lien n'est pas valide" },
29+
uri: { protocols: ["http", "https"], message: "Le lien n'est pas valide" },
3030
length: { maximum: 255, message: "Le lien est trop long" }
3131

3232
before_validation do |bookmark|

0 commit comments

Comments
 (0)