# Problem with params

**URL:** <https://www.ruby-forum.com/t/problem-with-params/55607>\
**Category:** Rails\
**Created:** [March 22, 2006, 12:28pm UTC](https://www.ruby-forum.com/t/problem-with-params/55607 "2006-03-22T12:28:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Preethi\_Naveen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/919ad9/32.png) [@Preethi\_Naveen](https://www.ruby-forum.com/u/Preethi_Naveen)\
**Post date:** [March 22, 2006, 12:28pm UTC](https://www.ruby-forum.com/t/problem-with-params/55607/1 "2006-03-22T12:28:56Z")

</div>

Hello,

I am trying to create a new record in a database by modifying the create  
method generated by scaffold. I have a situation where i want to add new  
student and while creating a new student, i am able to choose the  
department  
the student belongs to. However when i say create, i get an error saying  
that Department expected, got string.

_Parameters_: {“commit”=\>“Create”, “student”=\>{“department”=\>“1”}

the method

def create  
@student = Student.new(params[:student]) #error caused at this line  
if @student.save  
:  
end

The department field is of type integer  
so it looks like it expects an integer value while department returns a  
string. How do i convert it to an integer so that i can succesfully add  
a  
new student to the database

thanks  
Naveen

---

<div class="post-metadata">

**Author:** ![Preethi\_Naveen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/919ad9/32.png) [@Preethi\_Naveen](https://www.ruby-forum.com/u/Preethi_Naveen)\
**Post date:** [March 22, 2006, 12:54pm UTC](https://www.ruby-forum.com/t/problem-with-params/55607/2 "2006-03-22T12:54:20Z")

</div>

Hi,

I think even if you use integer you will still get similar error,  
except it will say Fixnum instead of string.  
Because it seems like :department should be of object Department, not  
the foreign key.

Cheers,  
Andy

---

<div class="post-metadata">

**Author:** ![Preethi\_Naveen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/919ad9/32.png) [@Preethi\_Naveen](https://www.ruby-forum.com/u/Preethi_Naveen)\
**Post date:** [March 22, 2006, 12:59pm UTC](https://www.ruby-forum.com/t/problem-with-params/55607/3 "2006-03-22T12:59:35Z")

</div>

Hi,

In your model you could explicitly state the relationship

class Student \< ActionRecord::Base  
belongs\_to :department, :class\_name=“department”, :foriegn\_key =\>  
‘department\_id’  
end

Then in the veiw use  
\<%= text\_field “student”, “department\_id” %\>

or similar for a select box.

I had similar problems when I was trying to get a form working and found  
that by doing this it worked. I think there is supposed to be some  
rails  
magic that does this for you but I don’t seem to have much luck with it.

Cheers

---

<div class="post-metadata">

**Author:** ![Preethi\_Naveen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/919ad9/32.png) [@Preethi\_Naveen](https://www.ruby-forum.com/u/Preethi_Naveen)\
**Post date:** [March 22, 2006, 11:06pm UTC](https://www.ruby-forum.com/t/problem-with-params/55607/4 "2006-03-22T23:06:02Z")

</div>

Yes… It follows the belong\_to requirements. But when you state is  
specifically the field name could be any name of type int.

---

<div class="post-metadata">

**Author:** ![Preethi\_Naveen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/919ad9/32.png) [@Preethi\_Naveen](https://www.ruby-forum.com/u/Preethi_Naveen)\
**Post date:** [March 22, 2006, 1:23pm UTC](https://www.ruby-forum.com/t/problem-with-params/55607/5 "2006-03-22T13:23:54Z")

</div>

is the foreign key department\_id a field in the main table student?

On 3/22/06, Liquid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Then in the veiw use
> 
> > Andy  
> > department  
> > line
> > 
> > > 
> > 
> > * * *

–  
Dattatraya
