Two difficult things for me to start using Playframework:
Bare controller isn’t useful
For example, it doesn’t support authenticating user. What I do in my application is that I’d make BaseController that offers:
def async[R](
bodyParser: BodyParser[R]
)(
fn: Context[R] => Future[Result]
): Action[R] = Action.async(bodyParser) { implicit request =>
// get user from cookies
// instantiate Context (which contains info about authenticated user
fn(context)
}
Then, in my normal controller, I’d would async
instead of using Action.async
. Context
will be injected to everywhere because the info about logged-in user is often needed everywhere.
This is heavyweight, and I imagine it’s difficult for a new user to solve a problem like this because it’s an architecture problem and requires a bunch of boilerplate.
Rails doesn’t seem to have this problem because we can authenticate user and store it in @loggedInUser
. We don’t have to pass Context
around like what I do in Playframework.
Writing tests
This is also very heavyweight. I had to make things like:
lazy val app = new GuiceApplicationBuilder()
.configure(Configuration.from(generateAppConfig))
.in(Mode.Test)
.build()
Reset database before every and run evolution with app.injector.instanceOf[EvolutionsApi].applyFor("default")
.
For a selenium test, I’d need to start the Play server with:
lazy val testServer = TestServer(
port = BaseSpec.PORT,
application = BaseSpec.app)
testServer.start()
These things seem undocumented. I imagine it would be super hard for new users to know these things (e.g. running evolution through code).
For tests to look nice, it requires a bunch of boilerplate as well.
Rails doesn’t require me to do all these things. We just install a gem, and that’s it. I think it’s the power of Ruby’s monkey patching.
The best thing about Playframework and Scala
I feel we should advertise this more. I use Playframework and Scala because of (1) type safety and (2) brevity (well, more concise than other typed languages and other frameworks).
For Rails, it becomes exponentially more difficult to maintain as the codebase grows. Rails and Ruby is very punishing if we delay upgrading gems or Rails’ version itself.
I used to maintain a 5-year old Rails, which was still on the version 3. It was a nightmare. Couldn’t upgrade a gem because it conflicted with another gem. Couldn’t find good documentation for a certain gem because the gem was old.