title: Ruby on Rails Route Model Binding
body: <p>I’ve semi-recently begun working with Ruby/Rails. As a frequent user of Laravel (and Spring), I’ve been delighted to find that Rails follows a similar convention, and supports many of the features I’ve come to love in Laravel. One feature that I have not been able to get a concise answer on though, is if Rails allows for what Laravel defines as “Route Model Binding”. Essentially, you define your route to your controller, and in your controller’s rest methods, you can do something like:</p>
  <pre class="lang-php prettyprint-override"><code>public function put(Account $account, Account $accountData)
  {
    $this-&gt;validateParms($accountData);
    $account.save($accountData);
  }
  </code></pre>
  <p>Even when using Spring, Jaxson allows for similar automagic object serialization in method routing</p>
  <pre class="lang-java prettyprint-override"><code>@PutMapping(&quot;/account/{id}&quot;)
  public ResponseEntity&lt;?&gt; updateAccount(@PathVariable int accountId, @RequestBody AccountDto accountDto) 
  {
    ...
    Account account = mapper.map(accountDto, Account.class);
    accountService.updateAccount(account);
    ...
  } 
  </code></pre>
  <p>So I'm essentially wondering if Rails offers some sort of similar automagic sugar, without having to do a before_action hook</p>
  <pre class="lang-rb prettyprint-override"><code>class AccountController &lt; ApplicationController
    before_action :getModel
  
    def getModel
      @current_account = Account.find_by_id(params[:id])
    end
  
    def update_account(account_data)
      @current_account.update(account_data)
    end
  end 
  </code></pre>