# Accepts\_nested\_attributes\_for abilities

**URL:** <https://www.ruby-forum.com/t/accepts-nested-attributes-for-abilities/183216>\
**Category:** Rails\
**Created:** [February 10, 2010, 2:18am UTC](https://www.ruby-forum.com/t/accepts-nested-attributes-for-abilities/183216 "2010-02-10T02:18:54Z")\
**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 10, 2010, 2:18am UTC](https://www.ruby-forum.com/t/accepts-nested-attributes-for-abilities/183216/1 "2010-02-10T02:18:54Z")

</div>

Is there a way to use accepts\_nested\_attributes\_for to update another  
table from within a controller. For example, I have this in my students  
controller:

def student\_fail  
@student = Subject.find(params[:id]) if params[:id]  
@student.build\_student\_fail  
end

def student\_fail\_finalize  
if @student.update\_attributes params[:student]  
@subject.save  
end  
end

I have this model relationship:

Student  
has\_one :student\_fail  
accepts\_nested\_attributes\_for :student\_fail, :allow\_destroy =\> true

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

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

From the students controller, when the user fills out a form, I just  
want to update that information to the student\_fail table. Can I achieve  
this through the controller using accepts\_nested\_attributes\_for? I don’t  
want to add anything to the view that indicates the other model. I’m  
hoping to do it directly in the controller. Thanks for any suggestions.

---

<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 10, 2010, 2:24am UTC](https://www.ruby-forum.com/t/accepts-nested-attributes-for-abilities/183216/2 "2010-02-10T02:24:48Z")

</div>

John M. wrote:

> Is there a way to use accepts\_nested\_attributes\_for to update another  
> table from within a controller. For example, I have this in my students  
> controller:
> 
> def student\_fail  
> @student = Subject.find(params[:id]) if params[:id]  
> @student.build\_student\_fail  
> end
> 
> def student\_fail\_finalize  
> if @student.update\_attributes params[:student]  
> @subject.save  
> end  
> end
> 
> I have this model relationship:
> 
> Student  
> has\_one :student\_fail  
> accepts\_nested\_attributes\_for :student\_fail, :allow\_destroy =\> true
> 
> StudentFail  
> belongs\_to :student\_fail\_state  
> belongs\_to :student
> 
> StudentFailState  
> has\_many :students, :through =\> :student\_fail  
> has\_many :student\_fails
> 
> From the students controller, when the user fills out a form, I just  
> want to update that information to the student\_fail table. Can I achieve  
> this through the controller using accepts\_nested\_attributes\_for? I don’t  
> want to add anything to the view that indicates the other model. I’m  
> hoping to do it directly in the controller.

Then you don’t need accepts\_nested\_attributes\_for.

However, the controller is the wrong place to sort out the attributes.  
Do it in a model or introduce a presenter class. Generally speaking,  
any but the most rudimentary logic does not go in the controller.

> Thanks for any suggestions.

Best,  
–Â  
Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
