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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:20:15+00:00 2026-05-26T12:20:15+00:00

In my relationships_controller I have the following: class RelationshipsController < ApplicationController def new @user_id

  • 0

In my relationships_controller I have the following:

class RelationshipsController < ApplicationController

  def new
    @user_id = User.find_by_id(params[:user_id])
    @relationship = Relationship.new
  end

  def create
    @relationship = Relationship.new(params[:relationship])
    @relationship.rel_id = User.find_by_id(params[:user_id])
    @relationship.user_id = current_user
    if @relationship.save
        redirect_to root_url, :notice => "Signed Up!"
    else
        render "new"
    end
  end
end

and in my views I have:

<section id="main">
  <%= form_for [@user_id, @relationship]  do |f| %>
    <div class="field">
      <%= f.label :type %>
      <%= select_tag(:type, options_for_select([['Friend', 0], ['Family', 1],['Spouse', 2]])) %>
    </div>
   <div class="actions"><%= f.submit %></div>
  <% end %>
</section>

I have a few questions:

  1. Is this the correct way to handle the rel_id and the user_id? It seems kinda clunky to me.

  2. I can’t get the :type to save to the database, but everything else does. I find the following in my server logs:

Parameters: {"utf8"=>"✓", "authenticity_token"=>"z7R4tWSSVHZmFXfh8HocfyuegZ2rwuXXeTLKbR+cLfs=", "type"=>"0", "commit"=>"Create Relationship", "user_id"=>"7"}

which seems odd to me because it should be saving type.

3.. Does it matter if I use @user_id or @current user in the <%= form_for [@user_id, @relationship] do |f| %> line? Why?

  • 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-26T12:20:15+00:00Added an answer on May 26, 2026 at 12:20 pm

    1) @user_id is actually assigned an instance of User, so I would call it @user
    when assigning rel_id I think you just need the user id value (integer). You can probably just do this:

    @relationship.rel_id = params[:user_id]
    

    2) type fields are used for STI tables with ActiveRecord, and bad things happen if you name your field type for any other reason. Try changing it to another name like relationship_type

    3) Possible, depending on how your app is set up. It’s possible that @user(_id) and @current_user represent different users. If you only want the current user to create a relationship for himself/herself, then you can just use @current_user (and maybe not use nested routes in that case).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my relationships_controller I have the following: class RelationshipsController < ApplicationController def new @user
lets say i have the following relationship: class Event < ActiveRecord::Base has_many :tickets end
I have the following associations class User < ActiveRecord::base has_many :memberships end What I
I'm new to OS X programming but generally liking it. I have the following
I have the following: Routes: . . . resources :users do resources :relationships end
I have a user model with a HABTM relationship to groups. I do not
I have the following model and relationship: Table: Granddad GranddadID GranddadName Table: Father FatherID
I have the following models: require 'books_projects.rb' class Project < ActiveRecord::Base has_many :book_to_projects has_many
I have a method that looks like the following in my controller: def some_request
I have the following relationships set up: A HABTM B B belongsTo C C

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.