Skip to content
This repository was archived by the owner on May 20, 2024. It is now read-only.

Commit 8b67c5b

Browse files
committed
Simplify code using latest helpers
1 parent 97f6cf0 commit 8b67c5b

File tree

5 files changed

+12
-30
lines changed

5 files changed

+12
-30
lines changed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ gem 'jbuilder', '~> 1.2'
2929

3030
gem 'yajl-ruby', require: 'yajl'
3131

32-
gem 'prismic.io', '~> 1.4.0', require: 'prismic'
32+
gem 'prismic.io', '~> 1.4.1', require: 'prismic'
3333

3434
# A gem to build simple paginations
3535
gem 'kaminari'

Gemfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ GEM
5757
minitest (4.7.5)
5858
multi_json (1.7.9)
5959
polyglot (0.3.3)
60-
prismic.io (1.4.0)
60+
prismic.io (1.4.1)
6161
hashery (~> 2.1.1)
6262
rack (1.5.2)
6363
rack-test (0.6.2)
@@ -123,7 +123,7 @@ DEPENDENCIES
123123
jbuilder (~> 1.2)
124124
jquery-rails
125125
kaminari
126-
prismic.io (~> 1.4.0)
126+
prismic.io (~> 1.4.1)
127127
rails (= 4.0.0)
128128
rails_12factor
129129
sass-rails (~> 4.0.0)

app/controllers/application_controller.rb

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ class ApplicationController < ActionController::Base
44

55
protect_from_forgery with: :exception
66

7-
# Rescue OAuth errors for some actions
7+
# Rescue bad preview cookies errors for some actions
88
rescue_from Prismic::Error, with: :clearcookies
99

1010
# Homepage action: querying the "everything" form (all the documents, paginated by 20)
1111
def index
1212
@google_id = api.experiments.current
13-
@documents = api.form("everything")
14-
.page(params[:page] ? params[:page] : "1")
15-
.page_size(params[:page_size] ? params[:page_size] : "20")
16-
.submit(ref)
13+
@documents = api.all({
14+
"page" => params[:page] ? params[:page] : "1",
15+
"page_size" => params[:page_size] ? params[:page_size] : "20",
16+
"ref" => ref
17+
})
1718
end
1819

1920
# Single-document page action: mostly, setting the @document instance variable, and checking the URL
@@ -22,7 +23,7 @@ def document
2223
slug = params[:slug]
2324

2425
@google_id = api.experiments.current
25-
@document = PrismicService.get_document(id, api, ref)
26+
@document = api.getByID(id, {"ref" => ref})
2627

2728
# This is how an URL gets checked (with a clean redirect if the slug is one that used to be right, but has changed)
2829
# Of course, you can change slug_checker in prismic_service.rb, depending on your URL strategy.

app/models/prismic_service.rb

-19
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,6 @@ def init_api
1818
Prismic.api(config('url'), access_token)
1919
end
2020

21-
def oauth_initiate_url(access_token, oauth_opts)
22-
access_token ||= self.access_token
23-
Prismic.oauth_initiate_url(config('url'), oauth_opts, access_token)
24-
end
25-
26-
def oauth_check_token(access_token, oauth_opts)
27-
access_token ||= self.access_token
28-
Prismic.oauth_check_token(config('url'), oauth_opts, access_token)
29-
end
30-
31-
# Gets a document from its ID.
32-
def get_document(id, api, ref)
33-
documents = api.form("everything")
34-
.query("[[:d = at(document.id, \"#{id}\")]]")
35-
.submit(ref)
36-
37-
documents.length == 0 ? nil : documents.first
38-
end
39-
4021
# Checks if the slug is the right one for the document.
4122
# You can change this depending on your URL strategy.
4223
def slug_checker(document, slug)

config/prismic.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
2-
url: https://lesbonneschoses.prismic.io/api
2+
url: https://lesbonneschoses-vcerzcwaaohojzo.prismic.io/api
33
# If specified this token is used for all "guest" requests
44
# token: ""
55
# OAuth2 configuration
66
# client_id: ""
77
# client_secret: ""
88

9-
# This file can contain ERB; for instance: client_id: <%= ENV['CLIENT_ID'] %>
9+
# This file can contain ERB; for instance: client_id: <%= ENV['CLIENT_ID'] %>

0 commit comments

Comments
 (0)