John Merlino
2010-Feb-20 01:16 UTC
update user input to another table without using html form
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. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Sharagoz --
2010-Feb-20 16:39 UTC
Re: update user input to another table without using html form
> @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 htmlAre 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. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
John Merlino
2010-Feb-20 17:53 UTC
Re: update user input to another table without using html form
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. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Matt Jones
2010-Feb-20 20:06 UTC
Re: update user input to another table without using html form
On Feb 19, 8:16 pm, John Merlino <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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] > endYou 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 Jones -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.