# Updating attributes of another model

**URL:** <https://www.ruby-forum.com/t/updating-attributes-of-another-model/183197>\
**Category:** Rails\
**Created:** [February 9, 2010, 9:37pm UTC](https://www.ruby-forum.com/t/updating-attributes-of-another-model/183197 "2010-02-09T21:37:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [February 9, 2010, 9:37pm UTC](https://www.ruby-forum.com/t/updating-attributes-of-another-model/183197/1 "2010-02-09T21:37:50Z")

</div>

I hve a relationship like this in my model:  
Student  
has\_one :student\_fail

StudentFail  
belongs\_to :student\_fail\_state  
belongs\_to :student

StudentFailState  
has\_many :students, :through =\> :student\_fail  
has\_many :student\_fails

In terms of the controller, what would be the best way to update  
attributes to the student\_fails table?

Here’s the view stuff:

resources\_form\_helper.rb:  
def render\_form\_collection\_field(form, name, label = nil, size = nil)  
render\_form\_field(form, name, label) do  
params = yield  
form.collection\_select name, params[:collection],  
params[:value\_method],params[:text\_method], {}, {:size =\> size}  
end  
end

def render\_form\_field(form, name, label=nil)  
label ||= name.to\_s.gsub(/_id$/, ‘’).gsub(’_’, ’ ')  
label\_class = “error” if error\_fields.include?(name.to\_sym)  
\<\<END\_HTML

- #{form.label name, label, :class =\> label\_class} 
#{yield}
END\_HTML end view: [render\_form\_collection\_field(f, :student\_fail\_state\_id, 'level') { { :collection =\> StudentFailState.true, :value\_method =\> :id, :text\_method =\> :name} }] #:student\_fail\_state\_id doesn't currently working because it's not in the student table.

Any suggestions on how to update other tables from a dropdown menu?  
Thanks.

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [February 9, 2010, 10:11pm UTC](https://www.ruby-forum.com/t/updating-attributes-of-another-model/183197/2 "2010-02-09T22:11:55Z")

</div>

[http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes](http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes)
