Forum: Ruby on Rails best practices for simple query

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.
Vapid B. (Guest)
on 2006-02-21 19:54
(Received via mailing list)
I have a very simple form that looks allows an input for an error code
and then give the show page from the scaffolding if the error code is
in the database and a notification on the list page, again from the
scaffolding if not.

Here's the form:
find.rhtml
<h1>Find error</h1>
<%= start_form_tag :action => 'search'%>
<p><label for="message_code">Code</label><br/>
<%= text_field 'message', 'code'  %></p>
  <%= submit_tag 'Search' %>
<%= end_form_tag %>

<%= link_to 'Back', :action => 'list' %>

Here's the method, search in the controller

  def search
    code=params[:message]["code"]
    @message = Message.find_by_code(code)
    if @message.nil?
        #render :action => 'find'
        flash[:notice] = "Code #{code} not found!\n Please choose a
code from this list"
        flash[:error] = 'Boom'
        redirect_to :action => 'list'
    else
        redirect_to :action => 'show', :id => @message
    end
  end

It works except for the fact that flash[:error] does not display and
in fact if I try :error for the first flash, it will not display.

Aside from this problem is their a better way to do this. I have the
agile book and googled quite a bit to finally find how to pass
non-database elements from a form to the controller, but I've lost the
link. I'm new to web apps so I don't know what the accepted practice
is for something like this so any helpful advise or criticism is
appreciated.

--
-vapid
This topic is locked and can not be replied to.