klionkind.blogg.se

Heroku rails master key
Heroku rails master key







add ( :main_image, "must be a JPEG or PNG" ) end end add ( :main_image, "is too big" ) end acceptable_types = unless acceptable_types. To do that, we add a declaration in the appropriate model like so:ĭef acceptable_image return unless main_image. Suppose, for example, we want our Event model to have one attached image-the main image for the event. The database is now ready to join any ActiveRecord model to a blob (an uploaded image), but we still need to declare associations in our models. So with these two pieces of information-a foreign key and a class name-the row knows exactly which record it’s referencing. Here’s the takeaway: The active_storage_attachments table joins any ActiveRecord model to its images (or attachments) because it’s a polymorphic join table. The second row in the active_storage_attachments table has a foreign key pointing to the user (because User is in the record_type column) and a foreign key pointing to the blob. It knows the record_id is a foreign key for an event, in this case, because the record_type column contains Event. Notice the first row in the active_storage_attachments table has a foreign key pointing to the event and another foreign key pointing to the blob.

heroku rails master key

For example, here’s a polymorphic join table that joins an event to it’s uploaded image and a user to it’s uploaded image:

heroku rails master key heroku rails master key

But it wouldn’t know what type of record it’s pointing to! 😲īy adding the polymorphic: true option, the migration creates two columns: a column named record_id which contains a foreign key and a column named record_type which contains the name of an ActiveRecord model class. If the polymorphic: true option weren’t added here, then the migration would simply create a column named record_id which would contain a foreign key pointing to a record. This means that the record it’s referencing can be any ActiveRecord model. references :record, null: false, polymorphic: true, index: false









Heroku rails master key