Forum: Ruby on Rails how to get flash errors to display in edge?

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.
15858fbf2415754bf7524e02e5df1469?d=identicon&s=25 adam (Guest)
on 2007-05-19 14:52
Hi

I have the following action, that generates a flash message if a blog is
created,


how can I get this message to display in my views?

thanks

#
    # POST /blogs
    # POST /blogs.xml
    def create
        @blog = Blog.new(params[:blog])

        respond_to do |format|
            if @blog.save
                flash[:notice] = 'Blog was successfully created.'
                format.html { redirect_to blog_url(@blog) }
                format.xml  { head :created, :location =>
blog_url(@blog) }
            else
                format.html { render :action => "new" }
                format.xml  { render :xml => @blog.errors.to_xml }
            end
        end
    end
78e258248fa0c682fec8c18c66532625?d=identicon&s=25 Andrei Maxim (Guest)
on 2007-05-19 15:04
(Received via mailing list)
On 5/19/07, adam <rails-mailing-list@andreas-s.net> wrote:
> thanks
>                 format.html { redirect_to blog_url(@blog) }
> Posted via http://www.ruby-forum.com/.
>
> >
>


--
Andrei Maxim
http://andreimaxim.ro
15858fbf2415754bf7524e02e5df1469?d=identicon&s=25 adam (Guest)
on 2007-05-19 15:17
I understand that that should pass teh flash hash to the page view,
however when I do somthing like this, nothing is displayed.

If the <%if flash-%> part is removed, an error is shown on most pages
due to a nil object.

any suggestions?

<%if flash-%>
    <%if flash[:notice] || flash[:alert] -%>
        <p id="flashMessage" class="message <%= flash[:notice] ? 'good'
: 'bad' -%>">
            <%= flash[:notice] || flash[:alert] %>
        </p>
    <% end -%>
<%end-%>

Andrei Maxim wrote:
> On 5/19/07, adam <rails-mailing-list@andreas-s.net> wrote:
>> thanks
>>                 format.html { redirect_to blog_url(@blog) }
>> Posted via http://www.ruby-forum.com/.
>>
>> >
>>
>
>
> --
> Andrei Maxim
> http://andreimaxim.ro
This topic is locked and can not be replied to.