Wondering if anyone can help with these issues I''m encountering in a
controller I''m developing.
I have a FAQ controller which stores sections and questions in a
database, allowing them to be added and edited online. Recently I
implemented RedCloth as a site-wide templating language, and
encountered an issue when trying to update my FAQ items to remove the
HTML tags. Here''s my code:
class FaqController < ApplicationController
. . .
def edit_question
@question = Question.find(@params[''id''])
end
def update_question
@question =
Question.find(@params[''question''][''id''])
if @question.update_attributes(@params[''question''])
flash[''notice''] = ''Question was successfully
updated.''
expire_page :action => "index"
redirect_to :action => ''index''
else
render_action ''edit_question'' # Tried appending :id
=> @question.id
end
end
. . .
end
However, when I update the question I receive the following error:
ActiveRecord::RecordNotFound in Faq#edit_question
Couldn''t find Question with ID=update_question
/app/controllers/faq_controller.rb:25:in `edit_question''
script/server:49
. . .
Request
Parameters: {"id"=>"update_question",
"question"=>{"answer"=>"<p>This is
merely filler for now.</p>\r\n\r\n<p>Add another paragraph for even
more
filler.</p>", "number"=>"1",
"section_id"=>"1", "id"=>"1",
"question"=>"What''s
WhatsSoFunny?"}}
Show session dump
--- {}
Response
Headers: {"cookie"=>[],
"Cache-Control"=>"no-cache"}
Show template parameters
---
rescues_path:
/usr/lib/ruby/gems/1.8/gems/actionpack-1.4.0/lib/action_controller/templates/rescues/
flash: {}
My edit_views/faq/edit_question.rhtml looks like:
<h1>Editing question</h1>
<%= error_messages_for ''question'' %>
<form method="post" action="update_question">
<%= hidden_field "question", "id" %>
<p>Question number: <%= text_field "question",
"number" %><br/>
Section:
<%= collection_select "question", "section_id",
Section.find_all, "number", "title" %><br/>
Question: <%= text_field "question", "question"
%><br/>
Answer:<br/>
<%= text_area "question", "answer" %>
<input type="submit" value="Update question"/>
</p></form>
<%= link_to ''Back'', :action => ''index''
%>
Somehow @params["id"] seems to be getting set to the action, and
I''m
not sure why. Even passing :id in to the render_action that reloads
the edit_question action doesn''t seem to change things.
What am I missing? What other information can I provide to help others
help me to track this down?
I''m not immediately seeing a problem with your code, but one thing to try would be to use the form_tag form helper method: <%= form_tag :action => "update_question", :id => @question.id %> You can also use <%= end_form_tag %> to finish it, but it just spits out a "</form>" tag. Duane Johnson (canadaduane) On Tue, 25 Jan 2005 16:56:07 -0600, Nolan J. Darilek <nolan-BEppJtBJOObp4W7C3Lsfgg@public.gmane.org> wrote:> Wondering if anyone can help with these issues I''m encountering in a > controller I''m developing. > > I have a FAQ controller which stores sections and questions in a > database, allowing them to be added and edited online. Recently I > implemented RedCloth as a site-wide templating language, and > encountered an issue when trying to update my FAQ items to remove the > HTML tags. Here''s my code: > > class FaqController < ApplicationController > . . . > def edit_question > @question = Question.find(@params[''id'']) > end > > def update_question > @question = Question.find(@params[''question''][''id'']) > if @question.update_attributes(@params[''question'']) > flash[''notice''] = ''Question was successfully updated.'' > expire_page :action => "index" > redirect_to :action => ''index'' > else > render_action ''edit_question'' # Tried appending :id => @question.id > end > end > . . . > end > > However, when I update the question I receive the following error: > > ActiveRecord::RecordNotFound in Faq#edit_question > > Couldn''t find Question with ID=update_question > > /app/controllers/faq_controller.rb:25:in `edit_question'' > script/server:49 > . . . > Request > > Parameters: {"id"=>"update_question", "question"=>{"answer"=>"<p>This is > merely filler for now.</p>\r\n\r\n<p>Add another paragraph for even more > filler.</p>", "number"=>"1", "section_id"=>"1", "id"=>"1", "question"=>"What''s > WhatsSoFunny?"}} > > Show session dump > > --- {} > > Response > > Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"} > > Show template parameters > > --- > rescues_path: /usr/lib/ruby/gems/1.8/gems/actionpack-1.4.0/lib/action_controller/templates/rescues/ > flash: {} > > My edit_views/faq/edit_question.rhtml looks like: > > <h1>Editing question</h1> > > <%= error_messages_for ''question'' %> > > <form method="post" action="update_question"> > <%= hidden_field "question", "id" %> > <p>Question number: <%= text_field "question", "number" %><br/> > Section: > <%= collection_select "question", "section_id", Section.find_all, "number", "title" %><br/> > Question: <%= text_field "question", "question" %><br/> > Answer:<br/> > <%= text_area "question", "answer" %> > <input type="submit" value="Update question"/> > </p></form> > > <%= link_to ''Back'', :action => ''index'' %> > > Somehow @params["id"] seems to be getting set to the action, and I''m > not sure why. Even passing :id in to the render_action that reloads > the edit_question action doesn''t seem to change things. > > What am I missing? What other information can I provide to help others > help me to track this down? > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Nolan J. Darilek wrote:> Wondering if anyone can help with these issues I''m encountering in a > controller I''m developing. > > I have a FAQ controller which stores sections and questions in a > database, allowing them to be added and edited online. Recently I > implemented RedCloth as a site-wide templating language, and > encountered an issue when trying to update my FAQ items to remove the > HTML tags. Here''s my code: > > class FaqController < ApplicationController > . . . > def edit_question > @question = Question.find(@params[''id'']) > end > > def update_question > @question = Question.find(@params[''question''][''id'']) > if @question.update_attributes(@params[''question'']) > flash[''notice''] = ''Question was successfully updated.'' > expire_page :action => "index" > redirect_to :action => ''index'' > else > render_action ''edit_question'' # Tried appending :id => @question.id > end > end > . . . > end > > However, when I update the question I receive the following error: > > ActiveRecord::RecordNotFound in Faq#edit_question > > Couldn''t find Question with ID=update_question > > /app/controllers/faq_controller.rb:25:in `edit_question'' > script/server:49 > . . . > Request > > Parameters: {"id"=>"update_question", "question"=>{"answer"=>"<p>This is > merely filler for now.</p>\r\n\r\n<p>Add another paragraph for even more > filler.</p>", "number"=>"1", "section_id"=>"1", "id"=>"1", "question"=>"What''s > WhatsSoFunny?"}}You can see that id is getting trounced here, it''s both "update_question" and "1".> My edit_views/faq/edit_question.rhtml looks like: > > <h1>Editing question</h1> > > <%= error_messages_for ''question'' %> > > <form method="post" action="update_question"> > <%= hidden_field "question", "id" %>Fix this by passing the question ID to the form method. You can do it like: action="<%= url_for(:controller => ''faq'', :action => ''update_question'', :id => @question.id) %>" Or you can use the form_tag helper. -Scott _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails