FAQ Database Discussion Community


can't upload attachement with has_one

ruby-on-rails,paperclip,has-one
Hi I am having issues with paperclip with a has_one association: track.rb class Track < ActiveRecord::Base belongs_to :lesson has_attached_file :track, :path => ":rails_root/public/system/lessons/tracks//:id/:basename.:extension", :url => "/system/lessons/tracks/:id/:basename.:extension" validates :track, attachment_content_type: { content_type: [ 'audio/mpeg', 'audio/x-mpeg', 'audio/mp3', 'audio/x-mp3', 'audio/mpeg3', 'audio/x-mpeg3', 'audio/mpg', 'audio/x-mpg', 'audio/x-mpegaudio' ]} end lesson.rb class Lesson <...

Rails 4 has_one - always overwrites first record

ruby-on-rails-4,has-one
First I thought this is a validation issue but then realized that every time a record gets saved it just overwrites the first record. List.rb belongs_to :user, :foreign_key => "user_id" In my modell I have: create_table "lists", force: :cascade do |t| t.text "pont12" t.datetime "created_at", null: false t.datetime "updated_at", null:...

How to declare objects for nested form in rails 4

ruby-on-rails,ruby-on-rails-4,nested-forms,has-one
I'm approaching my 2nd week of using rails, and have almost gotten the structure of my app complete (I think/hope). I'm building a staff website for a charity, which as part of their work collects and wipes computers (before sending them to African schools!). I've set up my app to...

Rails4 ActiveRecord has_one :conditions key removed

ruby-on-rails-4,activerecord,has-one
I am converting a RoR3.2 app to v4.2. In some models we have this construct: # A correspondent can have only one currently active client role or # it may have none. has_one :active_client, :class_name => 'Client', :conditions => IsActiveRow I am getting this error: Unknown key: :conditions. Valid keys...

:dependent => :destroy doesn't work on has_one relation

ruby-on-rails,has-one,dependent-destroy
In my models class User < ActiveRecord::Base has_one :user_detail, dependent: :destroy end and class UserDetail < ActiveRecord::Base belongs_to :user end When I call destroy for an User object, the associated UserDetail object is not being destroyed. Here's a test (of course, it fails because user_detail is not nil): test "associate...

Rails4 - Child model association depending on Parent model attribute

ruby-on-rails,ruby-on-rails-4,model,has-one
I have a User model that has an occupation attribute. Let's say a user can be a footballer or a tennisman When the user sign up, he selects the occupation, and can change it later. My User model contains the most common attributes, like name, address, weight, contact infos. I...

Is it a good idea to use has_one nested attributes in rails?

ruby-on-rails,nested-attributes,has-one
Let's say if I have 3 models; Hotel, Resort and restaurant. Each model have similar attributes; title, description, facilities ...and so on... If I want every models have one location with attributes; Country, Province, City, address, Latitude and Longitude. Should I create location model and using has_one nested attributes or...