Forum: Ruby on Rails Not updating

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3324a49b1605f0e2df7676ff64f5e712?d=identicon&s=25 Mohammad Ruby (mohammad)
on 2006-04-26 18:21
I copied the scaffolding edit and update and made it like this,

Note: awnser is edit.

Admin_contoller.rb

def awnser
  @question = Question.find(params[:id])
end

def update
  @question = Question.find(params[:id])
  if @question.update_attributes(params[:question])
    flash[:notice] = 'Question was successfully updated.'
    redirect_to :action => 'list'
  else
    render :action => 'edit'
    flash[:notice] = "Edit failed"
  end
end

Awnser.rhtml
<h1>Awnsering question</h1>

<%= start_form_tag :action => 'update', :id => @question %>

<p><%= @question.question %></p>

<p><label for="questions_awnser">Awnser</label><br/>
<%= text_area 'questions', 'awnser'  %></p>

  <%= submit_tag 'Awnser' %>
<%= end_form_tag %>

It flashes that it works but it really dosn't change the question.awnser
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2006-04-26 19:09
(Received via mailing list)
Hi Mohammad,

I might be misunderstanding your question but if, when your "Note" says
'awnser is edit' you mean that you don't have an 'edit' aciton in your
controller, then you might need to render :action => 'awnser' instead of
render :action =" 'edit'.

hth,
Bill

----- Original Message -----
From: "Mohammad" <name.goes.here44@gmail.com>
To: <rails@lists.rubyonrails.org>
Sent: Wednesday, April 26, 2006 11:21 AM
Subject: [Rails] Not updating
0a36dd2d45a8cead5dcfd27a9346f620?d=identicon&s=25 Mohammad (Guest)
on 2006-04-26 21:59
Bill Walton wrote:
> Hi Mohammad,
>
> I might be misunderstanding your question but if, when your "Note" says
> 'awnser is edit' you mean that you don't have an 'edit' aciton in your
> controller, then you might need to render :action => 'awnser' instead of
> render :action =" 'edit'.
>
> hth,
> Bill

I did change this I thought that that would be it but, no that didn't
work it still thinks that it is updating it when its not, I made sure
that there was no more typos for changing the names and there didn't
appear to be any. Im not sure what is going on.
4daf0b71d5d9a3882e583c0e72eaf5dc?d=identicon&s=25 Alan Francis (Guest)
on 2006-04-26 22:05
Mohammad  wrote:

> Awnser.rhtml
> <h1>Awnsering question</h1>
>
> <%= start_form_tag :action => 'update', :id => @question %>
>
> <p><%= @question.question %></p>
>
> <p><label for="questions_awnser">Awnser</label><br/>
> <%= text_area 'questions', 'awnser'  %></p>

That text_area needs to be 'question', 'awnser', singlualr question, not
plural questions

and if the db field is string, rather than text, it should probably be a
text_field, rather than a text_area.

Hope this helps,

Alan
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2006-04-26 22:13
(Received via mailing list)
If you'd post your code, it'll probably jump out at someone.  If you do,
please explain the problem you're having again.

Best regards,
Bill
----- Original Message -----
From: "Mohammad" <name.goes.here44@gmail.com>
To: <rails@lists.rubyonrails.org>
Sent: Wednesday, April 26, 2006 2:59 PM
Subject: [Rails] Re: Not updating
Df5dde68a3ac1251dda21d182fbcdb18?d=identicon&s=25 Owen Stenseth (Guest)
on 2006-04-26 22:53
(Received via mailing list)
Mohammad,

You need to save the model after you update it.

@question = Question.find(params[:id])
@question.update_attributes(params[:question])
if @question.save
   ...
Df5dde68a3ac1251dda21d182fbcdb18?d=identicon&s=25 Owen Stenseth (Guest)
on 2006-04-26 23:03
(Received via mailing list)
Oops, I guess update_attributes does a save. My bad.
0a36dd2d45a8cead5dcfd27a9346f620?d=identicon&s=25 Mohammad (Guest)
on 2006-04-27 03:39
Alan thanks this is what I did wrong, once again thanks Alan.
This topic is locked and can not be replied to.