📜 ⬆️ ⬇️

A pair of rakes in Ruby [on Rails] (absolute noob's guide)

Languages ​​and technologies I learn by multiplying cones on the forehead. You'll find yourself on such a rake - you will save at least some space on your forehead

ruby-debug-ide and mkmf


Ubunthos can face such a disaster: when installing gem ruby-debug-ide, the installer complains about the absence of some mkmf and refuses to continue. And sudo has nothing to do with it. Don't look for a matching gem, look better at the system package manager (aptitude, Synaptic or Adept or the powerful apt-get and dpkg :)). In addition to the logical for programmers, build-essential should also have ruby[X]-dev (where [X] is your preferred version of Ruby, most likely you have 1.8, i.e. ruby1.8-dev package). After installing it, repeat the command to install ruby-debug-ide, everything will go like clockwork.

The advice basically applies to all libraries with a native extension in the heart.
')
Fans of jruby will have to avoid packages with native extensions - look for package versions that have been -jruby .

habtm: id in the table of associations


habtm - this is abbreviated as has_and_belongs_to_many (if there are problems, look at the forums both this way and that). It needs an association table consisting of only id of two objects to be linked. And if it is easy to get rid of the timestamps, then the id column as the primary key is created without our knowledge and can spoil a lot of blood on such noobs like me. To get rid of it, you do not need to do one extra migration. The code for creating an association table might look like this:

  class CreateOnesTwos <ActiveRecord :: Migration
   def self.up
     create_table: ones_twos,: id => false do | t |  # he, additional parameter: id
       t.references: one
       t.references: two
     end
   end

   def self.down
     drop_table: ones_twos
   end
 end

Source: https://habr.com/ru/post/49269/


All Articles