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

  • Home
  • SEARCH
  • 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 8337803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:23:59+00:00 2026-06-09T04:23:59+00:00

I have two models, user and treating (which you can think of as a

  • 0

I have two models, user and treating (which you can think of as a message).

User:

class User < ActiveRecord::Base
    attr_accessible :name, :email, :password, :password_confirmation
    has_secure_password

    has_many :sent_treatings, :foreign_key => "requestor_id", :class_name => "Treating", dependent: :destroy
    has_many :received_treatings, :foreign_key => "requestee_id", :class_name => "Treating", dependent: :destroy

end

Treating:

class Treating < ActiveRecord::Base
  attr_accessible :intro, :proposed_date, :proposed_location

  validates :intro, presence: true, length: { maximum: 190 }
  validates :requestor_id, presence: true
  validates :requestee_id, presence: true

    belongs_to :requestor, class_name: "User"
    belongs_to :requestee, class_name: "User"

    default_scope order: 'treatings.created_at DESC'

end

I’m having trouble in my treatings controller setting ‘requestee’:

class TreatingsController < ApplicationController
    before_filter :signed_in_user

    def create
        requestee = ?
        requestor = current_user
        @received_treating = requestee.received_treatings.build(params[:treating])
        @received_treating.requestor = requestor

        if @received_treating.save
            flash[:success] = "Treating request sent!"
            redirect_to users_path
        else
            render 'static_pages/home'
        end
    end
end

The question mark I tried to replace with: User.find(params[:id]), hoping that the user in the current ‘users/show’ view would be found, but I get this error:

Couldn’t find User without an ID

I also tried User.find(params[:treating][:requestee_id]), but this didn’t work either. Any ideas?

Thanks!

EDIT:

views/shared/_treating_form.html.erb (this references @received_treating in the users controller, show action):

<div class="field">
    <%= f.text_area :intro, placeholder: "Write your introduction here..." %>
</div>

<%= f.submit "Send", class: "btn btn-large btn-primary" %>

EDIT: adding other user profile page:

<% provide(:title, @user.name) %>
<div class="row">
    <aside class="span4">
        <section>
            <h1>
                <%= gravatar_for @user %>
                <%= @user.name %>
            </h1>
        </section>
        <% if signed_in? %>
            <section>
                    <%= render 'shared/treating_form' %>
            </section>
        <% end %>
    </aside>
    <div class="span8">
        <% if @user.received_treatings.any? %>
        <h3>Treating requests (<%= @user.received_treatings.count %> received)</h3>
        <ol class="treatings">
            <%= render @received_treatings %>
        </ol>
            <%= will_paginate @received_treatings %>
        <% end %>
    </div>
</div>
  • 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-09T04:24:00+00:00Added an answer on June 9, 2026 at 4:24 am

    I think just adding @user.id in a hidden_field would work.

    <%= f.hidden_field :requestee_id, :input_html => { :value => @user.id }
    <div class="field">
        <%= f.text_area :intro, placeholder: "Write your introduction here..." %>
    </div>
    
    <%= f.submit "Send", class: "btn btn-large btn-primary" %>
    

    You could also populate the field doing

    <%= form_for @user.received_treatings.build do %>
      <%= f.hidden_field :requestee_id %>
      ....
    

    On the controller just do

    @received_treating = current_user.sent_treatings.build params[:treating]
    

    I have some doubts if this works but I think it should help you out.

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

Sidebar

Related Questions

I have two models: User (email:string) Profile (name:string) class User < ActiveRecord::Base has_one :profile
I have these two models user : class User < ActiveRecord::Base attr_accessible :name, :provider,
I have two models class User < ActiveRecord::Base has_one :user_information, :dependent => :destroy attr_accessible
I have two models: User and Teacher : class User < ActiveRecord::Base attr_accessor :password
Let's say I have two models like so: class Comment < ActiveRecord::Base belongs_to :user
Let's say I have two models like so: class Comment < ActiveRecord::Base belongs_to :user
Hey, need a little help here. I have two models: class User < ActiveRecord::Base
I have two models: User and Store class Store < ActiveRecord::Base belongs_to :user class
I have two models class User < ActiveRecord::Base has_one :work end class Work <
I have two models class User < ActiveRecord::Base has_many :requests, :foreign_key => :recipient_id .

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.