Not updating


#1

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

Awnsering question

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

<%= @question.question %>

Awnser
<%= text_area 'questions', 'awnser' %>

<%= submit_tag ‘Awnser’ %>
<%= end_form_tag %>

It flashes that it works but it really dosn’t change the question.awnser


#2

Bill W. 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.


#3

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” removed_email_address@domain.invalid
To: removed_email_address@domain.invalid
Sent: Wednesday, April 26, 2006 11:21 AM
Subject: [Rails] Not updating


#4

Mohammad wrote:

Awnser.rhtml

Awnsering question

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

<%= @question.question %>

Awnser
<%= text_area 'questions', 'awnser' %>

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


#5

Mohammad,

You need to save the model after you update it.

@question = Question.find(params[:id])
@question.update_attributes(params[:question])
if @question.save


#6

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” removed_email_address@domain.invalid
To: removed_email_address@domain.invalid
Sent: Wednesday, April 26, 2006 2:59 PM
Subject: [Rails] Re: Not updating


#7

Alan thanks this is what I did wrong, once again thanks Alan.


#8

Oops, I guess update_attributes does a save. My bad.