Take the 2-minute tour ×


  1. I have a form_for mapped to a model called List.
  2. List has attributes: name, id, receiver_id, assigner_id.
  3. I want the user( or list assigner) to be able to choose a list receiver.
  4. I want the assigner to input an e-mail, rather than the receiver's id.


  1. I am not sure how to use a form to receive an e-mail address, run a "User.find_by_email(xx).id" query using that e-mail address, and then assign the returned id to the List's receiver_id attribute.

Current Code:


class ListsController < ApplicationController

   before_filter :current_user

   def new
      @list = List.new

   def create
      @list = List.new(params[:list])
      @list.assigner = @current_user
      #@list.receiver = User.find_by_id(:receiver_id)
      redirect_to @list

   def show
      @list = List.find(params[:id])


   def update

@list = List.find(params[:id])



<%= form_for @list do |f| %>

    <%= f.label :name, 'Name'%>
    <%= f.text_field :name %>

    <%= f.label :receiver_id, 'Receiver ID'%>  
    **I want this to be the e-mail input, rather than the integer id.**
    <%= f.text_field :receiver_id %><br />

    <%= f.submit :submit %>

<% end %>
share|improve this question
add comment

2 Answers

User creates new list, with him as the assigner. In that creation process there must be a receiver too. Did I get this right?

I think the receiver should be selected from a list of possible receivers (maybe a select box? this will depend on the number of possible receivers though, wouldn't want to list 1000+ users in there - if there are many users you could do an ajax search when the user types a few letters)

The assigner then selects a user (with the corresponding id as the value) and everything should be ok.

share|improve this answer
Thanks Andrei that would work. Do you see any solution that might involve using a fields_for box? Something like <%= fields_for @list.receiver do |receiver_fields| %> ? –  Michael Chase Pell Oct 2 '11 at 22:00
add comment

The answer to my question is "Virtual Attributes..."

share|improve this answer
Congrats on the solution. When you are able, please add a little more detail or a link to a resource, and make sure to mark your answer as 'accepted' so that others might learn from your success. Cheers~ –  Andrew Kozak Dec 21 '11 at 19:14
add comment

Your Answer


