{"id":267,"date":"2022-08-30T14:58:30","date_gmt":"2022-08-30T14:58:30","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/08\/31\/problem-about-has-many-through-record-and-share-programming-errors\/"},"modified":"2022-08-30T14:58:30","modified_gmt":"2022-08-30T14:58:30","slug":"problem-about-has-many-through-record-and-share-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/problem-about-has-many-through-record-and-share-programming-errors\/","title":{"rendered":"problem about has-many-through-Record and share programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/354dbc60f05bbc3ea25cdf2c14540caf?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nHarish Shetty<br \/>\nruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1 has-many has-many-through<br \/>\nMy goal here is to print list of users from specified city and category with their names, address and club name.Name and address display correctly but when i add club name,says undefined method memberships for #.I know this is because Club is in different model ,So the question is how do i access club nam<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/b4832955447fe4e4b45b82209fa16d4e?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJLBaguio<br \/>\nruby-on-rails-3 devise has-many-through friend user-profile<br \/>\nI want a User(x) to be able to add another User(y) as a friend while User(x) is on User(y&#8217;s) Profile Page. I set up a has_many_through and everything works except that I can only add a friend from the User Index View. Thank you in advance&#8230;The code is below:Also:I wanted to place the &#8220;friend&#8221; link on the view\/profile\/show.html.erb. When I added @users = User.all to the existing profiles_controller.rb I received the error &#8211; undefined method friendships&#8217; for nil:NilClass. When I replaced @user = User.find(params[:id]) with @users = User.all I received the error &#8211; NoMethodError in Profiles#show&#8230; undefined methodinverse_friends&#8217; for nil:NilClassThe Code that works in UserIndexView but not ProfileShowView:% for user in @users %&gt;<\/p>\n<p>user), :method =&gt; :post%&gt;<\/p>\n<p>The following error occurs:NoMethodError in Profiles#showShowing \/Users\/mgoff1\/LOAP_1.2.2\/app\/views\/profiles\/show.html.erb where line #13 raised: undefined method `each&#8217; for nil:NilClass Extracted source (around line #13): 10: 11: 12: 13: 14: 15:<\/p>\n<p>16: <strong>:group_contacts, :conditions =&gt; {:groups =&gt; {:published =&gt; true}} endproblem happens when I try to instantiate a group from<\/strong><\/p>\n<\/li>\n<li><strong><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/72b0562f7e00f12976ebbd8c5e856236?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\njmorrissette<br \/>\nforms devise ruby-on-rails-3.2 has-many-through<br \/>\nThis would seem easy to do, basically I&#8217;m using Devise for administrative purposes, so every user signing up can create a product\/figure linked to their account then put up that product for a trade with another user.Class Userrolify:recoverable, :rememberable, :trackable, :validatableattr_accessible :role_ids, :as =&gt; :adminattr_accessible :email, :password, :password_confirmation, :remember_<\/strong><\/li>\n<li><strong><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/nyzNK.png?s=32&amp;g=1\" \/><br \/>\nPaul<br \/>\nruby-on-rails has-many-through acts-as-list<br \/>\nI am having an issue updating a has_many through record. Here is my setup:class TastingGroup &lt; ActiveRecord::Basehas_many :group_winehas_many :wines, through: :group_wine endclass GroupWine &lt; ActiveRecord::Basebelongs_to :tasting_groupbelongs_to :wine endclass W<\/strong><\/li>\n<li><strong><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/0db4f780adef8a8d24419bd48e824fb4?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nNathan Couch<br \/>\nruby-on-rails-3 foreign-keys has-many-through belongs-to nesting<br \/>\nThis is my first post here and to be honest, I don&#8217;t tend to ask many questions, but something has been irritating me for quite some time involving nesting in Ruby on Rails.I have a class Thought (which are members&#8217; individual posts) that are paginated as @share_items. I am including a like button that will allow members to like other members&#8217; posts (like Facebook). The like button has the class Opinion.My code thus far:Class Member has_many :thoughts, dependent: :destroy has_many :opinions, foreign_key: &#8220;fan_id&#8221;, dependent: :destroy has_many :fans, through: :opinionsClass Thought belongs_to :memberhas_many :opinions, foreign_key: &#8220;like_id&#8221;, dependent: :destroy has_many :likes, through: :opinionsvalidates :member_id, presence: trueClass Opinion attr_accessible :like_idbelongs_to :fan, class_name: &#8220;Member&#8221; belongs_to :like, class_name: &#8220;Thought&#8221;validates :fan_id, presence: true validates :like_id, presence: trueMember Model def share Thought.from_members_authenticated(self) endMemberPages Controller def homepage @share_items = registered_member.share.paginate(page:<\/strong><\/li>\n<li><strong><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/0c2f75ef598d989d6b947439b151931a?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ndaiikota<br \/>\nruby activerecord has-many-through mysql2<br \/>\nI ran into a little problem I have a has_many through relationship here is the code for the modelsclass User &lt; ActiveRecord::Basehas_many :friendshipshas_many :followings, :through =&gt; :friendships, :foreign_key =&gt; &#8220;followed_id&#8221; endclass Friendship &lt; ActiveRecord::Basebelongs_to :user belongs_to :following, :class_name =&gt; &#8220;User&#8221;, :<\/strong><\/li>\n<li><strong><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/086b3169fb1ba803945a292b75e1d4e4?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nsandovalg<br \/>\nruby ruby-on-rails-3.2 associations has-many-through nomethoderror<br \/>\nI am encountering a problem when trying to .build a new appointment. But first a look at my Model(s)class Patient &lt; ActiveRecord::Baseattr_accessible :address1, :address2, :city, :comment, :email, :first_name, :init_date, :init_time, :last_name, :mobile, :notes, :phone, :state, :zipbefore_validation :upcase_patientbefore_save { self.email.downcase! }has_many :appointments, dependent: :destroyhas_many :procedures, through: :appointmentsclass Procedure &lt; ActiveRecord::Baseattr_accessible :comment, :occurence, :procedure, :procedure_code, :procedure_price, :procedure_time, :visitsbefore_validation :uppercase_procedurehas_many :appointmentshas_many :patients, through: :appointmentsclass Appointment &lt; ActiveRecord::Baseattr_accessible :appointment_date, :appointment_notes, :appointment_time, :procedure_idbelongs_to :patientbelongs_to :procedureclass AppointmentsController &lt; ApplicationController include PatientsHelper before_filter :signed_in_userdef create@patient = current_patient@appointment = @patient.appointments.build(params[:appointment])if @appointment.saveflash[:success] = &#8220;Appointment scheduled!&#8221;redirect_to patient_path(@patient)elserender patient_path(@patient)end endmodule PatientsHelperdef current_patient=(patient)@current_patient = patientenddef current_patient@current_patientenddef current_patient?(patient)patient == current_pat<\/strong><\/li>\n<li><strong><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/1f32740d7e6c6d848679e06232cdd7d5?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ntvalent2<br \/>\nruby-on-rails-3 has-many-through nameerror<br \/>\nI&#8217;m new to Rails and am following Railscast #258 to implement jQuery TokenInput, and for some reason in trying to create a new record I&#8217;m getting the error:NameError: undefined local variable or method `through&#8217; for #from \/Library\/Ruby\/Gems\/1.8\/gems\/activerecord-3.0.5\/lib\/active_record\/base.rb:1008:in `method_missing&#8217;from \/Users\/Travis\/Desktop\/YourTurn\/app\/models\/tag.rb:4from \/Library\/Ruby\/Gems\/1.8\/gems\/activesupport-3.0.5\/lib\/active_support\/dependencies.rb:454:in `load&#8217;from \/Library\/Ruby\/Gems\/1.8\/gems\/activesupport-3.0.5\/lib\/active_support\/dependencies.rb:454:in `lo<\/strong><\/li>\n<li><strong><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/c0770bb3702176cbe1945a77dcbd09ec?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nbrad<br \/>\nruby-on-rails activerecord has-many-through<br \/>\nThis kind of goes along with my original question about has_many :through with conditions, but I&#8217;ve found another problem.Given this class:class Contact &lt; ARhas_many :group_contactshas_many :groups, :through =&gt; :group_contacts, :conditions =&gt; {:published =&gt; true}has_many :anonymous_groups, :through =&gt; :group_contacts, :source =&gt; :group, :conditions =&gt; {:anonymous =&gt; true} endMy problem happens wh<\/strong><\/li>\n<li><strong><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/HVyZu.png?s=32&amp;g=1\" \/><br \/>\nkeruilin<br \/>\nmysql ruby-on-rails has-many-through belongs-to<br \/>\nHere&#8217;s my User model:class User &lt; ActiveRecord::Basehas_many :friends, :class_name =&gt; &#8216;Friendship&#8217;, :dependent =&gt; :destroyendHere&#8217;s my Friendship model:class Friendship &lt; ActiveRecord::Bas<\/strong><\/li>\n<li><strong><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/f3b4c9f0fedbe30104a244f16f2d9bc8?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nvrish88<br \/>\nruby-on-rails has-many-through<br \/>\nI have a model, Feed, that has and belongs to many FilteredUsers. In this case I have implemented it through a has_many :through relationship.class Feed &lt; ActiveRecord::Basehas_many :denials, :depend<\/strong><\/li>\n<li><strong><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/79b84e97fab1f1e001a0f9e22a1ae326?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nAdgezaza<br \/>\nruby-on-rails has-many-through<br \/>\nI have a has_many and has_many :through relationship that looks like this&#8230;class Guestlist &lt; ActiveRecord::Basebelongs_to :venueshas_many :patronshas_many :users, :through =&gt; :patronsattr_accessible :capacity, :end_time, :name, :start_time,<\/strong><\/li>\n<li><strong><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/d1e178ec08ce223c9b1ef756aa181795?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nuser506706<br \/>\nruby-on-rails query has-many-through<br \/>\nI&#8217;m using Rails 2.3 and I have 3 tables, which manages user permissions to buildings. The mygroups table is the list of groups users and buildings belong to. The mygroupsbuildings is the list of buildings with their associated group. The mygroupsusers is the list of users with their associated group.create_table &#8220;mygroups&#8221;, :force =&gt; true do |t|t.string &#8220;name&#8221;t.integer &#8220;user_id&#8221;t.string &#8220;user_name&#8221;t.integer &#8220;permissions&#8221; endcreate_table &#8220;mygroupbuildings&#8221;, :force =&gt; true do |t|t.integer &#8220;mygroup_id&#8221;t.integer &#8220;building_id&#8221; endcreate<\/strong><\/li>\n<li><strong><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/729f689dc305c6a8a359b8a814a209bd?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nunlikely_monkey<br \/>\nruby-on-rails-3 activerecord has-many-through<br \/>\nI have three models:Class Project &lt; ActiveRecord::Basehas_many :taskshas_many :tags, :through =&gt; :tasks endClass Tasks &lt; ActiveRecord::Basebelongs_to :projecthas_and_belongs_to_many :tags endClass Tags &lt; ActiveRecord::Ba<\/strong><\/li>\n<li><strong><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/46311e8469a0f2d2340f182dd0c4a35a?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nkitensei<br \/>\nruby-on-rails activerecord has-many-through<br \/>\nI have the following structure:class Product &lt; ActiveRecord::Basehas_many :product_unitshas_many :units, :through =&gt; :product_units, :foreign_key =&gt; :unitID endclass Unit &lt; ActiveRecord::Basehas_many :product_unitshas_many :products, :through =&gt; :produc<\/strong><\/li>\n<li><strong><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/7df31594f04bb3a8727ddea3e062b43a?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ncmd<br \/>\nruby-on-rails ruby-on-rails-3 nested-forms has-many-through<br \/>\nI have a has many through relationship between my user and a vehicle.User has many Ownerships User has many vehicles through Ownerships.Ownerships belongs to User and VehicleVehicle has many Ownerships Vehicle has many Users through OwnershipsOn the vehicle show page I would like t<\/strong><\/li>\n<\/ul>\n<p id=\"rop\"><small>Originally posted 2013-08-31 07:48:17. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Harish Shetty ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1 has-many has-many-through My goal here is to print list of users from specified city and category with their names, address and club name.Name and address display correctly but when i add club name,says undefined method memberships for #.I know this is because Club is in different model ,So the question [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-267","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/267","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=267"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/267\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=267"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}