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 8223969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:53:44+00:00 2026-06-07T14:53:44+00:00

I have a unidirectional relationship model between users (users have many relationships) which holds

  • 0

I have a unidirectional relationship model between users (users have many relationships) which holds the ids of two given users along with user a’s nickname for user b. I want to use a form to allow users to pass in an e-mail address of another user and the nickname. If a user with that email exists, then create a relationship between the users. If no user matches, create a new ‘phantom’ user with that email and then build the relationship.

I’m relatively new to rails, and first naively tried using the basic:

= form_for @relationship do |f|
    = f.label :email
    = f.text_field :email
    = f.label :nickname, "Nickname"
    = f.text_field :nickname
    = f.submit "Submit", class: "btn btn-large btn-primary"

This fails because the relationship model does not contain an email attribute. I then tried the following, thinking it might work because it didn’t directly reference the relationship model.

= form_tag :controller => "relationships", :action => "create" do
    = label :email        
    = text_field :email
    = label :nickname, "Nickname"
    = text_field :nickname
    = submit "Submit", class: "btn btn-large btn-primary"

But that throws an error “wrong number of arguments (1 for 2)”

I could add an email field to the relationship model, but it’s not needed apart from when I’ll use it to look up the desired user. My plan was to use the email and nickname values passed to the create action in the relationship controller to either create the relationship or create a new user and then the relationship depending on the case. So how can I pass arbitrary values to a controller action?

  • 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-06-07T14:53:45+00:00Added an answer on June 7, 2026 at 2:53 pm

    Use the first form, and just make an attr_accessor in your model the email attribute.

    That basically makes a temporary variable that you can derive from something like a form, but it won’t save into the database.

    class Relationship < ActiveRecord::Base # <- Assuming that's the name of your Relationship model
    
      attr_accessor :email
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a relationship between two tables (both tables have their own primary
I have an Class with a unidirectional one to many relationship as follows: public
I have a one-to-one unidirectional relationship between a Booking object and an Address object
I have two entities with a Unidirectional Many-to-One mapping. Here's Product : use Doctrine\Common\Collections\ArrayCollection;
I'm using Grails and I want to have a unidirectional many-to-many relationship. In my
I have one-to-many relationship between parent and child Java objects. The parent object uses
I have 2 entities Item and Itemimage. The relationship between Item to Itemimage is
I am new to EF, and trying to get many-to-many unidirectional relationship with code
I have two examples that first is @OneToOne unidirectional mapping and second bidirectional. In
I have three classes: Location, MTFCC, and BorderPoint. Location has a unidirectional @ManyToOne relationship

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.