Hacker News new | past | comments | ask | show | jobs | submit | nicolasMLV's comments login

Rails uses foreign keys by default, usually I generate a migration file with `rails generate migration AddThisToThing this:references`

Then this line is generated `add_reference :things, :this, foreign_key: true`

and then we call the migration, and there is the foreign key.


Is it not more accurate to say "by default rails generates migrations with the foreign key argument set to a non default value of true"?

By default the relationship constructors do not create foreign keys, if they did it would be redundant to include it in the generated output surely? At least that's what the docs seem to say.


It is mainly a wrapper around this chrome headless command : (maybe you only need that)

`#{chrome_alias} --headless --disable-gpu --print-to-pdf="#{pdf_path}" "#{html_url}"`


Turbolinks is the official Front-end part of Rails and it works very well, but there is no mention of it in the article neither in the hackernews comments, so i think it is under-used.

There's also turbolinks-ios and turbolinks-android, I built my mobile apps with minimal knowledge of Swift and Kotlin.


I've transitioned from rails-everything to working exclusively with front-end frameworks and libraries (react, angular, polymer), and I'll tell you this still: if I'm working in rails, I use turbolinks. It's a wonderful approach, way under-appreciated.

When two or more things on the page need to know about each other/you require a high-fidelity interaction that you can't easily handle with just it, then yeah - reach for vue, react, or what have you. But no need to start there! Use those as targeted air strikes


I think the issue is that with out of the box rails apps, there's not a lot of opportunity to perform one of these 'targeted air strikes'. Emergent requirements incentivize quick solutions and you can end up with a bunch of ad-hoc foundation components and really bad jquery-ui slapped around in erb files.

At least, that's been my (very limited) experience with it.


I've found it easier to just drop in `react-rails` and build out react components for certain situations than to try and string a bunch of jquery together.


I love turbolinks as well. I can get < 100ms to screen with it without almost any extra effort.


Have to disagree on this one for anything but the most basic apps (think blogs and lots of static content). I'd have rewritten my entire app over by now with the "targeted air strikes" approach.


When turbolinks first hit most people went "oh it breaks jquery" and never touched it again.

Which is a shame considering how much it speeds most typical applications up by completely ignoring the mobile advantages.


Turbolinks just "works" so easily out of the box - for most use cases of persisting header / footer / etc between pages your users will think it's a "true" SPA. Even comes with the customizable css loading indicator now to re-enforce that feeling of speed.


David Heinemeier Hansson, CTO of Basecamp and Creator of Ruby on Rails https://www.twitter.com/dhh


You could simplify this

  <script>
    var counter = 0;
    $(document).ready(function() {
      var $output = $('#output');  
      $('#increment').click(function() {
        counter++;
        $output.html(counter);
      });
      $output.html(counter);
    });
 </script>
with

  <script>
    var counter = 0;
    $(document).on('click', '#increment', function() {
        counter++;
        $('#output').html(counter);
    });
  </script>


been using it for 1 year to swap keys (beer+keyboard accident...) and it works well


In 2013 I declined an offer (first job, graduate): software dev in bigco (IT Provider travel industry), £38K



I almost went down the event delegation route. The only thing that stopped me was having stumbled upon a tactic that happened to work where I just attached individualized event handlers one at a time. I appreciate the input and will make sure to give event delegation a second look.


You can use event delegation for button handling : `$(document).on('click', '.button-list', my_function);`

https://learn.jquery.com/events/event-delegation/


Thanks for posting this. It's sad how few people seem to know about event delegation...


Great but Turbolinks 5 and Action Cable (web sockets) are missing


Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: