# Passing values from partial to controller

**URL:** <https://www.ruby-forum.com/t/passing-values-from-partial-to-controller/188902>\
**Category:** Ruby\
**Created:** [May 20, 2010, 8:05am UTC](https://www.ruby-forum.com/t/passing-values-from-partial-to-controller/188902 "2010-05-20T08:05:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![drk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5ac83/32.png) [@drk](https://www.ruby-forum.com/u/drk)\
**Post date:** [May 20, 2010, 8:05am UTC](https://www.ruby-forum.com/t/passing-values-from-partial-to-controller/188902/1 "2010-05-20T08:05:34Z")

</div>

My partial:

```
        <p>
          <span title="Click to edit" id="edit_location">

```

\<%= link\_to grouprow.group\_name %\>

 \<%= custom\_button('Change') %\> 

```
        </p>
      </div>

```

 \<% form\_tag (:controller =\> "users" , :action =\> "addfriendtogroups") do %\>

```
Add friend:

```

\<%= text\_field\_with\_auto\_complete :user, ‘login’, {:size =\> 20},  
{:tokens =\> ‘,’} %\>

```
<%= hidden_field_tag :group_name ,grouprow.group_name %>
        <%= submit_tag "Add to group", :class =>

```

“submit\_input\_button rounded\_corner” %\>  
\<% end %\>

```
</div>

```

My controller:

def addfriendtogroups  
@f=User.find\_by\_login(params[:login])  
@g=Group.find\_by\_group\_name(params[:group\_name])

@addfriend=GroupFriend.create(:user\_id =\> current\_user.id,  
:group\_id =\> @g.id,:friend\_id =\> @f.id)

respond\_to do |format|

```
if @addfriend.save

flash[:notice] = "Friend added to group successfully."

```

format.html {redirect\_to :back}

```
end

end

```

end

I get the following error

RuntimeError in UsersController#addfriendtogroups

Called id for nil, which would mistakenly be 4 – if you really wanted  
the id of nil, use object\_id

Request

Parameters:

{“group\_name”=\>“testinggroup2”,  
“commit”=\>“Add to group”,  
“authenticity\_token”=\>“MHB8Ys8vccsGwbgnsb9r5T68oqirPpW6YUscfDojZhY=”,  
“id”=\>“testing”,  
“user”=\>{“login”=\>“santosh”}}

I need to fetch the id of login (santosh) from users table and id of the  
groupname (testinggroup2) from groups and insert the userid, friendid  
(id of santosh), groupid (id of testinggroup2) into another table.

Please help. Thanks.
