Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6529799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:40:44+00:00 2026-05-25T09:40:44+00:00

I have 2 types of users, one is called list_owner and one is called

  • 0

I have 2 types of users, one is called list_owner and one is called subscriber. These are both users made with devise. Subscribers should be able to follow the list_owner. I have another model called Relationship to keep track who the subscriber follows.

I used http://ruby.railstutorial.org/ mostly as an example.

These are the relations

class Relationship < ActiveRecord::Base

  attr_accessible :list_owner_id, :subscriber_id

  belongs_to :list_owner
  belongs_to :subscriber

end

class ListOwner < ActiveRecord::Base

  has_many :messages
  has_many :relationships, :dependent => :destroy, :foreign_key => "list_owner_id"

end

class Subscriber < ActiveRecord::Base

  has_many :relationships, :foreign_key => "subscriber_id",
                             :dependent => :destroy

 def follow!(list_owner)
      puts "-----------------------"

   relationships.create!(:subscriber_id => subscriber.id, :list_owner_id => list_owner.id)
 end

end

I made a list with list owners with a button where the subscriber can subscribe to.

<%= form_for current_subscriber.relationships.build(:list_owner_id => l.id, :subscriber_id => @subscriber.id),
                 :remote => true do |f| %>
    <%= f.hidden_field :list_owner_id %>
    <%= f.hidden_field :subscriber_id %>
    <%= f.submit "Subscribe", :class => "button btn" %>
<% end %>



class RelationshipsController < ApplicationController
  def create
    puts "---------------------relationships CREATE---------------------"
    @list_owner = ListOwner.find(params[:relationship][:list_owner_id])
    current_subscriber.follow!(@list_owner)
        redirect_to root_path
  end

end

This is the error i get. What am i doing wrong?

Started POST "/relationships" for 127.0.0.1 at Wed Sep 07 15:37:17 +0200 2011
  Processing by RelationshipsController#create as JS
  Parameters: {"commit"=>"Subscribe", "relationship"=>{"list_owner_id"=>"2", "subscriber_id"=>"1"}, "authenticity_token"=>"m5plsJLdzuwNt1yKfDJFKD28GcR138V+pezbfbECCPk=", "utf8"=>"✓", "_"=>""}
  ListOwner Load (0.2ms)  SELECT "list_owners".* FROM "list_owners" WHERE "list_owners"."id" = 2 LIMIT 1
  Subscriber Load (0.2ms)  SELECT "subscribers".* FROM "subscribers" WHERE "subscribers"."id" = 1 LIMIT 1
Completed 500 Internal Server Error in 34ms

NameError (undefined local variable or method `subscriber' for #<Subscriber:0x102f140c0>):
  app/models/subscriber.rb:21:in `follow!'
  app/controllers/relationships_controller.rb:8:in `create'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:40:45+00:00Added an answer on May 25, 2026 at 9:40 am

    There’s no such ‘subscriber’ object defined, but you don’t need one, since you’re calling the create!() method on the association collection, which will pre-populate the parent object. That is, calling subscriber.relationships.create! will set subscriber_id = subscriber.id.

    def follow!(list_owner)
      relationships.create!(:list_owner_id => list_owner.id)
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an type of document which users should not be able to read
I have two types of users for my system, normal human users with a
I have two types of users on the database: -Web registered users -Twitter users
I have several entities which respresent different types of users who need to be
I have a rails application that has three different types of users and I
I have a thread, and different users rating a movie in 3 different types.
I have two user types in my application: Investors and Advisors , they both
I'm new to these types of MySQL Queries. Basically, I have two tables in
I'm using sharepoint 2007. I have a list called User Tickets with one column
I have one custom ListView called AreasListView which I've included in the XML file.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.