# Update user input to another table without using html form

**URL:** <https://www.ruby-forum.com/t/update-user-input-to-another-table-without-using-html-form/183788>\
**Category:** Rails\
**Created:** [February 20, 2010, 2:16am UTC](https://www.ruby-forum.com/t/update-user-input-to-another-table-without-using-html-form/183788 "2010-02-20T02:16:21Z")\
**Posts on this page:** 9\
**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 20, 2010, 2:16am UTC](https://www.ruby-forum.com/t/update-user-input-to-another-table-without-using-html-form/183788/1 "2010-02-20T02:16:21Z")

</div>

Hey all,

Let’s say you are not going to use an html form. Rather the user will  
input data in a third-party application that will communicate with the  
rails controller through http requests, but serves as a replacement to  
the html. In other words, it’s taking the place of front end.

My question is can you update the attributes of another table, let’s say  
studentfails table, from let’s say a students controller (which has a  
students table) based on user input (the user input needs to be inserted  
in the studentfails table).

I was hoping something like this, but this doesn’t work:

student.rb  
has\_one :student\_fail  
attr\_accessor :student\_fail\_attribute

def find\_failing\_student  
@student = @student.find params[:id]  
end  
def update\_failing\_student  
@student = @student.find params[:id]  
@student.build\_student\_fail params[:student][:student\_fail\_attribute]  
end

Even for this you have to put student\_fail\_attribute in the html. I’m  
hoping there’s a way where you don’t have to put anything in the html.  
Any suggestions? Thanks for any response.

---

<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 20, 2010, 5:39pm UTC](https://www.ruby-forum.com/t/update-user-input-to-another-table-without-using-html-form/183788/2 "2010-02-20T17:39:52Z")

</div>

> @student = @student.find params[:id]  
> This makes no sense to me…

> Even for this you have to put student\_fail\_attribute in the html. I’m  
> hoping there’s a way where you don’t have to put anything in the html  
> Are you trying to say that you want to use a get request instead of a  
> post request? In a perfect world every request that changes the server  
> state is a post request, but if you want to use a get request just put  
> additional parameters in the url.

I suggest you make this work with a regular html view before worrying  
about the external front end.

---

<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 20, 2010, 6:53pm UTC](https://www.ruby-forum.com/t/update-user-input-to-another-table-without-using-html-form/183788/3 "2010-02-20T18:53:47Z")

</div>

Sharagoz – wrote:

> > @student = @student.find params[:id]  
> > This makes no sense to me…
> 
> > Even for this you have to put student\_fail\_attribute in the html. I’m  
> > hoping there’s a way where you don’t have to put anything in the html  
> > Are you trying to say that you want to use a get request instead of a  
> > post request? In a perfect world every request that changes the server  
> > state is a post request, but if you want to use a get request just put  
> > additional parameters in the url.

What do you mean by put additional parameters in the url? Thanks for the  
response though.

---

<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 21, 2010, 5:54pm UTC](https://www.ruby-forum.com/t/update-user-input-to-another-table-without-using-html-form/183788/4 "2010-02-21T17:54:53Z")

</div>

Matt J. wrote:

> On Feb 19, 8:16ï¿½pm, John M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > in the studentfails table).  
> > def update\_failing\_student  
> > ï¿½ @student = @student.find params[:id]  
> > ï¿½ @student.build\_student\_fail params[:student][:student\_fail\_attribute]  
> > end
> 
> You don’t appear to be _saving_ the result from  
> @student.build\_student\_fail. Either you’re looking for  
> create\_student\_fail (which saves the record) or something like:
> 
> def update\_failing\_student  
> @student = Student.find(params[:id])  
> @student\_fail = @student.build\_student\_fail(params[:student]  
> [:student\_fail\_attribute])  
> if @student\_fail.save  
> # save succeeded  
> else  
> # save failed - re-render form with errors  
> end  
> end
> 
> > Even for this you have to put student\_fail\_attribute in the html. I’m  
> > hoping there’s a way where you don’t have to put anything in the html.
> 
> Not sure what you’re looking for here: it’s going to be hard to get a  
> field from the user without asking for it…
> 
> –Matt J.

The form will be in the other application used as a front end, not in  
rails. So the user will put data in that form but I want it to update to  
another table, not the students table even though we capture the data in  
the students controller.

---

<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 20, 2010, 9:08pm UTC](https://www.ruby-forum.com/t/update-user-input-to-another-table-without-using-html-form/183788/5 "2010-02-20T21:08:06Z")

</div>

On Feb 19, 8:16 pm, John M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> in the studentfails table).  
> def update\_failing\_student  
> @student = @student.find params[:id]  
> @student.build\_student\_fail params[:student][:student\_fail\_attribute]  
> end

You don’t appear to be _saving_ the result from  
@student.build\_student\_fail. Either you’re looking for  
create\_student\_fail (which saves the record) or something like:

def update\_failing\_student  
@student = Student.find(params[:id])  
@student\_fail = @student.build\_student\_fail(params[:student]  
[:student\_fail\_attribute])  
if @student\_fail.save  
# save succeeded  
else  
# save failed - re-render form with errors  
end  
end

> Even for this you have to put student\_fail\_attribute in the html. I’m  
> hoping there’s a way where you don’t have to put anything in the html.

Not sure what you’re looking for here: it’s going to be hard to get a  
field from the user without asking for it…

–Matt J.

---

<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 21, 2010, 9:22pm UTC](https://www.ruby-forum.com/t/update-user-input-to-another-table-without-using-html-form/183788/6 "2010-02-21T21:22:03Z")

</div>

On Feb 21, 4:54 pm, John M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The form will be in the other application used as a front end, not in  
> rails. So the user will put data in that form but I want it to update to  
> another table, not the students table even though we capture the data in  
> the students controller.

Doesn’t make any difference - SomeModel.create(…) will work just as  
well in one controller as in another.

Fred

---

<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 21, 2010, 9:32pm UTC](https://www.ruby-forum.com/t/update-user-input-to-another-table-without-using-html-form/183788/7 "2010-02-21T21:32:34Z")

</div>

Frederick C. wrote:

> On Feb 21, 4:54ï¿½pm, John M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > The form will be in the other application used as a front end, not in  
> > rails. So the user will put data in that form but I want it to update to  
> > another table, not the students table even though we capture the data in  
> > the students controller.
> 
> Doesn’t make any difference - SomeModel.create(…) will work just as  
> well in one controller as in another.
> 
> Fred

Even if it’s a flash (adobe flex) form and not html form? The  
communication is done purely through http requests. For example, user  
clicks flash button, this triggers http put request, method is called in  
rails, data captured through the params function in rails, and thus data  
is subsequently updated to database. However, it’s not like I can stick  
an attribute created using attr\_accessor in that flash form.

---

<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 21, 2010, 11:02pm UTC](https://www.ruby-forum.com/t/update-user-input-to-another-table-without-using-html-form/183788/8 "2010-02-21T23:02:31Z")

</div>

> Even if it’s a flash (adobe flex) form and not html form?  
> A http request is a http request regardless of where it is submitted  
> from. Start by making this work with a rails view, and then worry about  
> the flash front end later. When you know what the http request actually  
> needs to look like, then its easier drop the rails view and implement an  
> external front end to replace it.

---

<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 21, 2010, 9:42pm UTC](https://www.ruby-forum.com/t/update-user-input-to-another-table-without-using-html-form/183788/9 "2010-02-21T21:42:33Z")

</div>

On Sun, Feb 21, 2010 at 12:32 PM, John M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Frederick C. wrote:

> > Doesn’t make any difference - SomeModel.create(…) will work just as  
> > well in one controller as in another.

> Even if it’s a flash (adobe flex) form and not html form? The  
> communication is done purely through http requests. For example, user  
> clicks flash button, this triggers http put request, method is called in  
> rails, data captured through the params function in rails, and thus data  
> is subsequently updated to database.

Yes, that’s the way the web works 🙂

> However, it’s not like I can stick an attribute created using attr\_accessor  
> in that flash form.

?? Either you’re passing the data you need to your controller via that  
request or you’re not. Which is it?

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan
