bizreach-inc / play2-hands-on Goto Github PK
View Code? Open in Web Editor NEWPlay2 + Slick / ScalikeJDBCを使ってWebアプリケーションを作成するハンズオンです。
Home Page: http://bizreach-inc.github.io/play2-hands-on/
Play2 + Slick / ScalikeJDBCを使ってWebアプリケーションを作成するハンズオンです。
Home Page: http://bizreach-inc.github.io/play2-hands-on/
ページ内リンクがhttpの時があるようなので様々なメリットがあるhttps側に寄せたい。
今あるhandsOnの英語版を作る。
元ソース
def list = Action { implicit request =>
DB.readOnly { implicit session =>
// ユーザのリストを取得
val users = withSQL {
select.from(Users as u).leftJoin(Companies as c).on(u.companyId, c.id).orderBy(u.id.asc)
}.map { rs =>
(Users(u)(rs), rs.intOpt(c.resultName.id).map(_ => Companies(c)(rs)))
}.list.apply()
// 一覧画面を表示
Ok(views.html.user.list(users))
}
}
下記のように val u = Users.syntax("u")
を追記することでコンパイルエラーは回避できました。
def list = Action { implicit request =>
val u = Users.syntax("u")
DB.readOnly { implicit session =>
// ユーザのリストを取得
val users = withSQL {
select.from(Users as u).leftJoin(Companies as c).on(u.companyId, c.id).orderBy(u.id.asc)
}.map { rs =>
(Users(u)(rs), rs.intOpt(c.resultName.id).map(_ => Companies(c)(rs)))
}.list.apply()
// 一覧画面を表示
Ok(views.html.user.list(users))
}
}
元ソース
"""{"users":[{"id":1,"name":"Taro Yamada","companyId":1},{"id":2,"name":"Jiro Sato"}]}"""
下記のように"companyId":null
を明記すると通る。nullを返すかどうかなのでバージョンや設定が関係しているかも?
"""{"users":[{"id":1,"name":"Taro Yamada","companyId":1},{"id":2,"name":"Jiro Sato","companyId":null}]}"""
In hugo v0.42.2,
$ hugo version
Hugo Static Site Generator v0.42.2 darwin/amd64 BuildDate: 2018-06-28T12:36:21Z
$ hugo
| EN
+------------------+----+
Pages | 88
Paginator pages | 5
Non-page files | 0
Static files | 69
Processed images | 0
Aliases | 10
Sitemaps | 1
Cleaned | 0
Total in 160 ms
But, in hugo v0.58.2
$ hugo version
Hugo Static Site Generator v0.58.2/extended darwin/amd64 BuildDate: unknown
$ hugo
# terminal
Building sites … WARN 2019/09/15 10:14:22 Page's .Hugo is deprecated and will be removed in a future release. Use the global hugo function.
WARN 2019/09/15 10:14:22 Page's .RSSLink is deprecated and will be removed in a future release. Use the Output Format's link, e.g. something like:
{{ with .OutputFormats.Get "RSS" }}{{ .RelPermalink }}{{ end }}.
WARN 2019/09/15 10:14:22 Page's .Dir is deprecated and will be removed in a future release. Use .File.Dir.
ERROR 2019/09/15 10:14:22 open /play2-hands-on/docs/play2.3-slick2.1/introduction.html: is a directory
ERROR 2019/09/15 10:14:22 open /play2-hands-on/docs/play2.5-scalikejdbc2.5/introduction.html: is a directory
ERROR 2019/09/15 10:14:22 open /play2-hands-on/docs/play2.5-slick3.1/introduction.html: is a directory
ERROR 2019/09/15 10:14:22 open /play2-hands-on/docs/play2.6-scalikejdbc3.2/introduction.html: is a directory
Total in 157 ms
Error: Error building site: failed to render pages: open /play2-hands-on/docs/play2.4-slick3.0/introduction.html: is a directory
HTML の Form は GET/POST 以外をリクエストすることができません。
現状は、 POST リクエストに hidden 属性で _method パラメータを付与したり、
submit イベントを JavaScript でフックして、 Ajax で PUT/DELETE リクエストを代行する
などの方法で回避されていますが、
POSTリクエストで、リクエストヘッダに"X-HTTP-Method-Override": "PUT"で、
POSTをPUTで上書きしたりしてるのですが、Playで、RESTfulなAPIを実現するには
どのようにしてformを拡張して、PUT,DELETEを実現してるのでしょうか?
playframework/playframework#5313
Expressだと、method-overrideというライブラリで、formのmethodを_methodパラメータで上書きしています。
https://github.com/expressjs/method-override/blob/master/index.js
$.ajax({
url: "http://localhost:10320/api/Person/4",
type: "POST",
data: JSON.stringify(whatever),
headers: {
"Content-Type": "application/json",
"X-HTTP-Method-Override": "PUT" },
})
ハンズオンの手順の説明で、「プロジェクトの作成」というページで登場するコマンドです。
例(play2.5-slick3.1):http://bizreach.github.io/play2-hands-on/play2.5-slick3.1/create_project.html
sbtをインストールする手順で実行するコマンドがこのように与えられています。
brew update
brew install sbt
↓
sbt sbt-version
しかし、現在brew install sbt
でインストールされるsbtのバージョン(2018/06/18現在 ver 1.1.6)ではsbt sbt-version
コマンドは廃止されており、代わりにsbt sbtVersion
コマンドを使います。
ドキュメントに点在するsbt sbt-version
コマンドを全て修正するプルリクを作らせて頂きたいのですが、よろしいでしょうか?
最後の Ok(Json.obj("users" -> users))
の箇所のimplicitが見つからないみたい?
ドキュメント通りにimport JsonController._
を書いてあるがダメ。
def list = Action { implicit request =>
val u = Users.syntax("u")
DB.readOnly { implicit session =>
// ユーザのリストを取得
val users = withSQL {
select.from(Users as u).orderBy(u.id.asc)
}.map(Users(u.resultName)).list.apply()
// ユーザの一覧をJSONで返す
Ok(Json.obj("users" -> users))
}
}
当該部分のコマンドをそのまま実行したところうまくいかず、scalikejdbcGen USERS と scalikejdbcGen COMPANIES のようにコマンドを2回に分けてひとつづつモデルを生成したところうまくいきました。お手数をおかけいたしますが、もしそちらでも同じ状態が確認できた場合に修正していただければ幸いです
Play2.7系がリリースされたのでサンプルプロジェクトとハンズオン手順ページを作成する。
各フォルダの説明や新規バージョンを追加する時などの進め方があった方が新規の協力者に優しそう。
hugoの簡単な説明なども。
WikiまたはREAD.MEなど。
過去バージョンを全て保持していると一括置換系の時の文言確認や動作確認が大変。
かなり古いバージョンは切り捨てたい。
最新バージョン+2世代くらいあれば問題ない気がする。
http://bizreach.github.io/play2-hands-on/play2.5-scalikejdbc2.5/preparation_of_db.html
こちらのページにて、build.sbt
にscalikejdbcSettings
を追加する手順が漏れていました。
手順に追加をお願い致します。
ローカルで hugo server
を実行してもリンク先に飛べない(URL直指定だとページは表示される)
config.toml
で uglyurls = true
となっているからローカルと本番用出力ファイルで差異があるのが原因な気がする。
初学者にとってScalikeJDBCは扱いやすいが、シェア的にSlickのサンプルも作成する。
ページ: http://bizreach.github.io/play2-hands-on/play2.5-scalikejdbc2.5/implement_user_list.html
正: @(users: Seq[models.Users])(implicit request: Request[Any])
誤: @(users: Seq[models.Accounts])(implicit request: Request[Any])
ページ数が増えてきて手動でメンテナンスするのが厳しくなってきたのでhugoを使ってGitHub Pagesで運用するようにする。
ハンズオンを用いて学習を進めていましたが、
2ページ目のプロジェクトの作成部分で、指示通り
sbt new playframework/play-scala-seed.g8
を実行するとバージョン2.6のテンプレートが作成されてしまいます。
このままsbt run を実行すると
abstractControllerが見つからないというエラーが発生してしまい、先に進めなくなってしまいます。
応急処置としてsbt new...を行う際に
sbt new playframework/play-scala-seed.g8 --branch 2.5.x
とバージョンを指定してプロジェクトを作成するという方法をとることでハンズオンは進めることができました。
このような事例がありましたことをご報告します。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.