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.
--
-john
--
The deep fascination of myths is that they speak directly to deeper
levels of our nature and to the subconscious, and give the profound
assurance that we are each, in essence, deathless and immortal sparks
of Divinity on the long evolutionary journey into higher consciousness.
- Sir George Trevelyn
Hi, Vapid, did you change anything on the scaffolded layout. In your view/layouts folder is there a scaffold layout for the controller? And in this layout: Is there display code for the flash notice? Regards Jan Prill On 2/27/06, Vapid Babble <vapidbabble@gmail.com> wrote:> > 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. > > -- > -john > -- > The deep fascination of myths is that they speak directly to deeper > levels of our nature and to the subconscious, and give the profound > assurance that we are each, in essence, deathless and immortal sparks > of Divinity on the long evolutionary journey into higher consciousness. > - Sir George Trevelyn > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060302/c3940c2b/attachment.html
I did everything in the generated controller, so I didn''t change the layout. I''m not sure about your last question? I just call flash. With :notice it works, with :error it does not. I''ll double check my Agile book but from what you are saying I didn''t supply the needed display code for error. On 3/2/06, Jan Prill <JanPrill@blauton.de> wrote:> Hi, Vapid, > > did you change anything on the scaffolded layout. In your view/layouts > folder is there a scaffold layout for the controller? And in this layout: Is > there display code for the flash notice? > > Regards > Jan Prill > > > On 2/27/06, Vapid Babble <vapidbabble@gmail.com> wrote: > > > 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. > > -- > -john > -- > The deep fascination of myths is that they speak directly to deeper > levels of our nature and to the subconscious, and give the profound > assurance that we are each, in essence, deathless and immortal sparks > of Divinity on the long evolutionary journey into higher consciousness. > - Sir George Trevelyn > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- -john --
Doesn''t look like you''re doing anything with flash[:error] in your view. The flash[:notice] shows up because the basic layout generated by scaffold puts <p style="color: green"><%= flash[:notice] %></p> in there... Try putting that with :error instead... bet yah it''ll work. b PS: I actually saved the model object in the flash on error, cuz that has all the errors in it. Then I can use error_messages_for in the view. Vapid Babble wrote:> I did everything in the generated controller, so I didn''t change the > layout. I''m not sure about your last question? I just call flash. > With :notice it works, with :error it does not. I''ll double check my > Agile book but from what you are saying I didn''t supply the needed > display code for error. > > On 3/2/06, Jan Prill <JanPrill@blauton.de> wrote: > >>Hi, Vapid, >> >>did you change anything on the scaffolded layout. In your view/layouts >>folder is there a scaffold layout for the controller? And in this layout: Is >>there display code for the flash notice? >> >>Regards >> Jan Prill >> >> >>On 2/27/06, Vapid Babble <vapidbabble@gmail.com> wrote: >> >> 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. >> >>-- >>-john >>-- >>The deep fascination of myths is that they speak directly to deeper >>levels of our nature and to the subconscious, and give the profound >>assurance that we are each, in essence, deathless and immortal sparks >>of Divinity on the long evolutionary journey into higher consciousness. >>- Sir George Trevelyn >>_______________________________________________ >>Rails mailing list >>Rails@lists.rubyonrails.org >>http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >>_______________________________________________ >>Rails mailing list >>Rails@lists.rubyonrails.org >>http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> > > > > -- > -john > -- > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails