Skip to content

Commit 29219c2

Browse files
committed
Update protip to use / as separator for url slug
1 parent e1b4d1f commit 29219c2

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

app/controllers/protips_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def show
135135
end
136136

137137
return redirect_to protip_missing_destination, notice: "The pro tip you were looking for no longer exists" if @protip.nil?
138-
return redirect_to protip_path(@protip.friendly_id, :p => params[:p], :q => params[:q]) if params[:id]!=@protip.friendly_id
138+
return redirect_to protip_path(@protip.public_id<<'/'<<@protip.friendly_id, :p => params[:p], :q => params[:q]) if params[:slug]!=@protip.friendly_id
139139
140140
@comments = @protip.comments
141141
@reply_to = show_params[:reply_to]
@@ -404,7 +404,7 @@ def expand_query(query_string)
404404
end
405405
406406
def lookup_protip
407-
@protip = if public_id = params[:id].split('--').first
407+
@protip = if public_id = params[:id]
408408
Protip.find_by_public_id(public_id.downcase)
409409
else
410410
nil

app/models/protip.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ def to_html
956956
end
957957

958958
def slug_format
959-
"#{public_id}--#{title}"
959+
"#{title}"
960960
end
961961

962962
protected

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@
289289

290290
resources :protips, :path => '/p' do
291291
collection do
292+
get ':id/:slug' => 'protips#show'
292293
get 'random'
293294
get 'search' => 'protips#search', as: :search
294295
post 'search' => 'protips#search'

spec/controllers/protips_controller_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ def valid_session
5454
protip = Protip.create! valid_attributes
5555
protip.save
5656
get :show, {id: protip.to_param}, valid_session
57-
expect(response).to redirect_to protip_path(protip.slug)
57+
expect(response).to redirect_to protip_path(protip)
5858
end
5959
end
6060

6161
describe "GET show using slug" do
6262
it "assigns the requested protip as @protip" do
6363
protip = Protip.create! valid_attributes
6464
protip.save
65-
get :show, {id: protip.friendly_id}, valid_session
65+
get :show, {id: protip.public_id, slug: protip.friendly_id}, valid_session
6666
expect(assigns(:protip)).to eq(protip)
6767
end
6868
end

0 commit comments

Comments
 (0)