Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Simply put: you are taking some steps way out of rails' philosophy</strong>. Rails is an opinionated framework and if you don't do things following the rails way, it is going to hurt.</p> <p>First of all, it is generally accepted in rails community that <strong>logic should not belong in the database, it should belong in your application</strong>. There's a lot of heated talk about this, but if you're going to use rails, you have to get used to it, because the framework is designed that way. So <strong>instead of a trigger, you should have used a callback in one of your models</strong>.</p> <p>Other than that, your <strong>controller code seems heavily bloated</strong>. It is encouraged to keep controller code extremely thin because it is much more maintainable and coherent with MVC architecture (the controller's responsibility should only be to instantiate model objects, perform an action on them, then instantiate a view). A common practice is to push such logic down to the models.</p> <p>Moreover, it <strong>seems that you don't care the least about naming conventions</strong>. If you don't follow the rails guidelines about this, you lose a lot of magic and wonder, and make your own life a lot harder. For example, if you had followed the conventions, you could write the controller code you posted this way : </p> <pre><code> usario = User.new( params[:user] ) usario.save render json: usario, status: 200 </code></pre> <p>That's 3 lines instead of 14.</p> <p>Finally, all of this denotes a lack of knowledge about the framework. I strongly encourage you to thoroughly (re-)read the <a href="http://guides.rubyonrails.org/" rel="nofollow">rails guides</a>, and possibly one or two of the many good books there are out there. This will give you a more precise idea of the workflow and design using this wonderful of a tool that is rails.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload