Forum: Ruby on Rails when using scaffold flash['notice']

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.
ss (Guest)
on 2006-04-21 19:29
Hi,

When using the scaffold standard new / create methods, on successful
completion of  creating a new database entry, is there any return
methods I cna pick up in a custom tempalte such as flash['notice']?

Thanks
Scott
Alex W. (Guest)
on 2006-04-21 20:09
ss wrote:
> Hi,
>
> When using the scaffold standard new / create methods, on successful
> completion of  creating a new database entry, is there any return
> methods I cna pick up in a custom tempalte such as flash['notice']?
>
> Thanks
> Scott

I'm not sure what your are asking but the flash is exactly how you send
data to the next action.  And the flash is just a standard hash that you
can fill with any keys you like.

flash[:array] = [1, 2, 3]
flash[:model] = BlogComment.find(123)
flash[:error_message] = 'Comment not saved due to an ugly error!'

If thats not what you were askign about to asking your question again as
it is a bit unclear.
ss (Guest)
on 2006-04-21 20:19
ok maybe it was a bit unclear.

When I create a custom template / def I can specify somthing like this
in my controller

flash['notice']  = "Client successfully removed"

and then use this in my rhtml, to show the message

<% if flash['notice'] %>
         <div id="good" class="message"><%= flash['notice']%></div>
<% end %>


When I havnt got any custom def's in my controller and am just using the
standard scaffold templates.

ie 'scaffold :clients' in my controller

Does it return any successful messages when an operation like create or
destroy has worked correctly, and how can I get hold of these?
Alex W. (Guest)
on 2006-04-21 20:40
ss wrote:
> ok maybe it was a bit unclear.
>
> When I create a custom template / def I can specify somthing like this
> in my controller
>
> flash['notice']  = "Client successfully removed"
>
> and then use this in my rhtml, to show the message
>
> <% if flash['notice'] %>
>          <div id="good" class="message"><%= flash['notice']%></div>
> <% end %>
>
>
> When I havnt got any custom def's in my controller and am just using the
> standard scaffold templates.
>
> ie 'scaffold :clients' in my controller
>
> Does it return any successful messages when an operation like create or
> destroy has worked correctly, and how can I get hold of these?

Oh I see, Well you're moving beyond the capabilites of scaffold here.
Scaffold is meant to be a quick and dirty start, but not something you
finish with.  Run this:

ruby script/generate scaffold Clients Client

This actually creates all the scaffold code and rhtml templates so you
can edit them.  Then you can go into the create and update methods and
get the hooks you need.  Making the base scaffold work for anything even
slightly complicated will only end in frustration.  Use it as a
srpingboard to modify and update.

But directly answering your question, the only response scaffold gives
about success is the flash.  And if the data is good, it does a
redirect, and if its bad it does a render.  Scaffold wasn;t really meant
for anything more complicted than that.
Bill W. (Guest)
on 2006-04-21 20:55
(Received via mailing list)
Just as a heads-up...

> ruby script/generate scaffold Clients Client

The above will generate a model named clients.rb.   That will probably
give
you problems down the road since the Rails naming conventions assume
that a
model's name will be the singular of the table name on which it is
based.  I
imagine that was just a typo, but it's caught me before so I thought I'd
point it out before you got too far down the road.

Best regards,
Bill
Alex W. (Guest)
on 2006-04-21 21:12
Bill W. wrote:
> Just as a heads-up...
>
>> ruby script/generate scaffold Clients Client
>
> The above will generate a model named clients.rb.   That will probably
> give
> you problems down the road since the Rails naming conventions assume
> that a
> model's name will be the singular of the table name on which it is
> based.  I
> imagine that was just a typo, but it's caught me before so I thought I'd
> point it out before you got too far down the road.
>
> Best regards,
> Bill

Yeah my bad, it should be

ruby script/generate scaffold Client Clients

The first parameter is the model name, and the second parameter is the
controller name, I get them confused sometimes.
Guest (Guest)
on 2006-04-24 12:10
>
> Yeah my bad, it should be
>
> ruby script/generate scaffold Client Clients
>
> The first parameter is the model name, and the second parameter is the
> controller name, I get them confused sometimes.


ok cool, thanks
This topic is locked and can not be replied to.