Skip to content

Instantly share code, notes, and snippets.

@colewinans
Created June 29, 2013 19:32
Show Gist options
  • Save colewinans/5892353 to your computer and use it in GitHub Desktop.
Save colewinans/5892353 to your computer and use it in GitHub Desktop.
has_many :through issue
class User < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation, :remember_me, :username, :profile_image, :first_name, :last_name
has_many :publications
has_many :threads, :through => :publications
end
class Publication < ActiveRecord::Base
attr_accessible :thread_id, :user_id
belongs_to :thread
belongs_to :user
accepts_nested_attributes_for :thread
end
class Thread < ActiveRecord::Base
attr_accessible :description, :name, :tag_list, :thumbnail_image, :status, :thread_type, :subtitle, :summary
has_one :publication
has_one :user, :through => :publication
end
# Begin form for creating new thread
= form_for [@user, @thread] do |f|
- if @thread.errors.any?
#error_explanation
%h2= "#{pluralize(@thread.errors.count, "error")} prohibited this thread from being saved:"
%ul
- @thread.errors.full_messages.each do |msg|
%li= msg
.field
%span Title:
= f.text_field :name
.actions
= f.submit 'Submit'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment