Rails Tutorial 5章
scss初めてちゃんと触ったかも。まぁまぁ良いじゃん。単品で使う気にはならないけれど。コンパイルがめんどくさそう。Railsみたいに仕組みが上手く動いていたらとても良いですね。
結合テストで怒られたので言われたとおりにgem入れる
Error: SiteLayoutTest#test_layout_links: NoMethodError: assert_template has been extracted to a gem. To continue using it, add `gem 'rails-controller-testing'` to your Gemfile. test/integration/site_layout_test.rb:9:in `block in <class:SiteLayoutTest>'
testがわからんからサイトよんだ
昔はRspecだった気がするのだけれど。
railsguides.jp
むかしはguardかけてGrowlに出すとかに血道を上げていたけど、いまはもう、`rails test`って普通に叩いて満足だもんな。
Rails Tutorial 2章~3章
croud9とか使ってないんじゃ。
rvmで2.4入れてるんじゃ。
rubyの界隈では最新に追いついておくのが定石。
最新でウガーっとうなるのがよくあるパターン。
コミュニティが活発なのでなんとかなる。
この場合、
github.com
これ食らう。
そこでGemfileをtutorialからちといじる
source 'https://rubygems.org' git_source(:github) do |repo_name| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") "https://github.com/#{repo_name}.git" end # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '5.0.1' # Use Puma as the app server gem 'puma', '3.4.0' # Use SCSS for stylesheets gem 'sass-rails', '5.0.6' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '3.0.0' # Use CoffeeScript for .coffee assets and views gem 'coffee-rails', '4.2.1' # See https://github.com/rails/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby # Use jquery as the JavaScript library gem 'jquery-rails','4.1.1' # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks gem 'turbolinks', '5.0.1' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '2.4.1' # Use Redis adapter to run Action Cable in production # gem 'redis', '~> 3.0' # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development group :development, :test do # Use sqlite3 as the database for Active Record gem 'sqlite3','1.3.11' # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug','9.0.0', platform: :mri end group :development do # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. gem 'web-console', '3.3.1' gem 'listen', '3.0.8' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring','1.7.2' gem 'spring-watcher-listen', '2.0.0' end group :production do gem 'pg','0.18.4' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
5.0.1で治らんというひともいるけど我が環境では治った。
成果物
Home | Ruby on Rails Tutorial Sample App
cloud9ちょっと昼休みに使ったけどコレすごい良いね。
Emacsいらんやんとおもったり。
Emacsには
qiita.com
qiita.com
を入れて現代風。
flymakeは古いんじゃー。まだ設定ファイルに残っているけど。整理しなきゃだね。
rails tutorial 5対応版を始めます
久々にRailsでも触ってみるかーと。
Railsの歴史的意義は終わったと思っているけれど、色々魅力的なフレームワークではある。Coffeeとか(今や)ニッチな方言覚えたくないけれど。
いつも間にか日本語版の翻訳がかなりすごいことになっているので今回は日本語版でやることにしました。
やっぱりね、英語、苦手だから。
一章終了。所要時間30分未満。日本語は英語より得意です。
Cloud9とかでやる感じになっているけれど老害な私はEmacs + iTermで。
herokuへのデプロイが異常に楽になってる感じします。もっと昔(Rails3の頃)は苦労したはず。
というかherokuのcliを入れた記憶がないが入っていた。なぞ。入れた記憶ないが。。*1
スカッといけて拍子抜け。
あのころよりも記憶を遡ってみれば内容が良くなっている部分があって、gemのバージョンをガッチガッチに指定しているところがサクッと進められる原因なんだろうな、と思います。
railsはどう進歩しているのだろう。次からが楽しみです。
いや、routes.rb変更したら再起動必要だった気がするんだけれど即座に反映されるしなんか変更あったのかな。
*1:前の個人プロジェクトがherokuで動かしてるからその時かな。。
Common IO
便利。
String str = FileUtils.readFileToString(new File("test.txt"), "utf-8"); List<String> list = FileUtils.readLines(new File("test.txt"), "utf-8");
追記 2017/02/04
[引用] package com.sample.foo.bar.baz; import java.io.File; public class GetCurrentPath { /** カレントパッケージ */ private static final String CURRENT_PACKAGE = GetCurrentPath.class.getPackage().getName(); /** カレントディレクトリ */ private static final String CURRENT_PATH = new File("").getAbsolutePath(); public static void main(String[] args) { System.out.println(CURRENT_PACKAGE); System.out.println(CURRENT_PATH); } }
コレ使えばいろいろ更に楽できそう。
RubyというかRailsの開発環境2017 ~結局Emacsだった~
最初はEmacs捨てたかった。
補完が欲しかった
Eclipse+Aptanaためした。
標準メソッドの補完は良かったけど自分で作ったクラスのメソッド補完はだめだった。
NetBeans試した
標準メソッドの補完は良かったけど自分で作ったクラスのメソッド補完はだめだった。
状況は一緒。
RubyMineは試していない。お高いもの。仕事でrubyでWEBサービスバリバリ使うわけではないのでちょっと手が出ない。多分良いのだろうけど。
それは昔、rsenseと言うものがEmacsにあってね、なかなか良かったのだけれど開発止まっているっぽい。
一応、forkして?やっている人がいるっぽいけど
github.com
まぁ、Javaが必要だったり大変。
codeout.hatenablog.com
こういうの見つけて、
自分で作ったクラスのメソッド補完が効くのでこれで良しとする。
Emacsキーバインド最高だしね!
rubyのダックタイピングがあるから実のところお馬鹿なauto-completeと相性良かったりする。
結局Emacs。
されど補完の効くEmacs。最強。
モダンではないけれどanythingとrinariもあるしまぁ、いい感じ。
設定ファイルに古いrubyのプラグインてんこ盛りなのでちょっとなんとかしたいところではある。
Java1.6のファイルの読み込みなー
BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream(resourceNatureOfInquiry), "UTF-8")); String str = br.readLine(); while (str != null) { System.out.println(str); m.put(str, str); str = br.readLine(); } } catch (Exception e) { e.printStackTrace(); // do nothing } finally { try { br.close(); } catch (Exception ex) { ex.printStackTrace(); // do nothing } }
追記 2017/2/1
Apache commons のcommon-ioでまるっと読み込むのが正しいのかも
JavaでSELECT結果とRETURNコードを吐き出すストアドを叩いて見る
ストアド
NorthWindをSQLServer2014 Expressにインストール
各インストール方法は割愛します。
対象プロシージャーは下記のようにちょっとかえてSELECT結果とreturnを返すようにしている。
USE [Northwind] GO /****** Object: StoredProcedure [dbo].[Employee Sales by Country] Script Date: 2017/01/27 15:37:04 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER procedure [dbo].[Employee Sales by Country] @Beginning_Date DateTime, @Ending_Date DateTime AS SELECT Employees.Country, Employees.LastName, Employees.FirstName, Orders.ShippedDate, Orders.OrderID, "Order Subtotals".Subtotal AS SaleAmount FROM Employees INNER JOIN (Orders INNER JOIN "Order Subtotals" ON Orders.OrderID = "Order Subtotals".OrderID) ON Employees.EmployeeID = Orders.EmployeeID WHERE Orders.ShippedDate Between @Beginning_Date And @Ending_Date RETURN 10
Java
これをJavaから叩いてみる。
別途MSからJDBCのjarをダウンロードして突っ込んでビルドパス通しておく。
あとは一般的なJDBCプロミングと変わらないけれど、
ResultSetの取得後にReturn値の取得という順番でいかないとダメっぽい。
import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; public class Main { private static final String JDBC_URL="jdbc:sqlserver://localhost:1433;databaseName=NorthWind"; private static final String USER = "sa"; private static final String PWD = "xxxxxx"; /** * @param args */ public static void main(String[] args) { Connection con = null; CallableStatement cs = null; ResultSet rs = null; String sql = "{? = call dbo.[Employee Sales by Country](@Beginning_Date = ? ,@Ending_Date = N'1997/07/01' )}"; try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); con = DriverManager.getConnection(JDBC_URL,USER,PWD); cs = con.prepareCall(sql); cs.registerOutParameter(1, java.sql.Types.INTEGER); cs.setDate(2, java.sql.Date.valueOf("1997-01-01")); if(! cs.execute()){ System.out.println("Execution failed"); } rs = cs.getResultSet(); while(rs != null && rs.next()){ System.out.print(rs.getObject(1) + "\t"); System.out.print(rs.getObject(2) + "\t"); System.out.print(rs.getObject(3) + "\t"); System.out.print(rs.getObject(4) + "\t"); System.out.print(rs.getObject(5) + "\t"); System.out.println(""); } // 順番大事 int retCode = cs.getInt(1); System.out.println(retCode); } catch (Exception e){ e.printStackTrace(); } finally { forceClose(rs); forceClose(cs); forceClose(con); } } private static void forceClose(AutoCloseable c) { if (c == null) { return; } try { c.close(); } catch (Exception ignore) { ignore.printStackTrace(); } } }
出力結果
USA Callahan Laura 1997-01-16 00:00:00.0 10380 USA Fuller Andrew 1997-01-01 00:00:00.0 10392 USA Davolio Nancy 1997-01-03 00:00:00.0 10393 USA Davolio Nancy 1997-01-03 00:00:00.0 10394 UK Suyama Michael 1997-01-03 00:00:00.0 10395 USA Davolio Nancy 1997-01-06 00:00:00.0 10396 ..... 10
10年ぶりにSQLServer触ったけどなかなかよいね。Management Studioのできはやはり秀逸。