Forum: Ruby on Rails Ajax Scaffold Generator for Rails Released

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.
Richard W. (Guest)
on 2006-02-25 23:38
(Received via mailing list)
I just released a whole new version of the Ajax Scaffold Generator (for
Ruby
on Rails). The generator creates a scaffold page like the typical rails
one,
except adding, editing and deleting are all done inline. The generated
scaffold is valid XHTML strict and fully styled right out of the box.

Check out the demo:

http://ajaxscaffold.height1percent.com/
And the how-to:

http://www.height1percent.com/articles/2006/02/21/...

Its a generates a much better starting point for an Ajax'ified
application
or for any application than the existing scaffold generator. I hope you
guys
find it useful.
Thanks.

--
Richard W.
Interface Designer
Blog | www.height1percent.com
Easy to use online calendar | www.kiko.com
Keep in touch with relatives | www.youlookfamiliar.com
Craig W. (Guest)
on 2006-02-26 00:02
(Received via mailing list)
On Sat, 2006-02-25 at 16:36 -0500, Richard W. wrote:
> And the how-to:
>
> http://www.height1percent.com/articles/2006/02/21/...
>
>
> Its a generates a much better starting point for an Ajax'ified
> application or for any application than the existing scaffold
> generator. I hope you guys find it useful.
----
looks impressive and I suspect that I will be playing with it soon. Nice
demo and description too.

Thanks

Craig
pat eyler (Guest)
on 2006-02-26 00:11
(Received via mailing list)
On 2/25/06, Craig W. <removed_email_address@domain.invalid> wrote:
> >
> demo and description too.
It does look good.   Good enough that I posted a message about it at
the Apress blog -- http://ablog.apress.com/?p=938

I can't wait to see how this fits in with a small app I'm doing at work.

>
> Thanks
>
> Craig
>
> _______________________________________________
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
thanks,
-pate
Ezra Z. (Guest)
on 2006-02-26 00:54
(Received via mailing list)
Very cool!

-Ezra
Leon L. (Guest)
on 2006-02-26 01:27
(Received via mailing list)
kool... but paging support would be excellent!
Brian (Guest)
on 2006-02-26 02:58
I downloaded this last night, and regenerated scaffolds for about half a
dozen models on one of my projects.  It is simply amazing.  I had no
hiccups, and it looks and works perfectly on every browser I threw at
it.  thanks for your hard work on this Richard.  (and unlike my earlier
email to Zed, I made sure to get your  name right).

Brian
Jim C. (Guest)
on 2006-02-26 04:33
(Received via mailing list)
On Sun, Feb 26, 2006 at 01:58:49AM +0100, Brian wrote:
> hiccups, and it looks and works perfectly on every browser I threw at
> it.


Well, I threw Opera 9 p2 (3216) under OSX at it, and when creating a
customer record received a JavaScript popup box "TableRow: both
parameters must be a <tr> tag."

It worked fine with Safari, and Firefox.

But, despite that - very nice :-)

-jim
Sean S. (Guest)
on 2006-02-26 04:42
(Received via mailing list)
Jim C. wrote:
>
> It worked fine with Safari, and Firefox.
>
> But, despite that - very nice :-)
>
> -jim
>
I got that same error also when trying the demo running Safari under
Tiger (intel).  However, I think it's something with the demo?  It was
random for me and seemed to only happen after a canceled Edit of a row.
After reloading the data I was able to edit again.

-Sean
David Olbersen (Guest)
on 2006-02-26 08:51
(Received via mailing list)
On Feb 25, 2006, at 1:36 PM, Richard W. wrote:

>
> http://www.height1percent.com/articles/2006/02/21/...
> scaffold-generator
> Its a generates a much better starting point for an Ajax'ified
> application or for any application than the existing scaffold
> generator. I hope you guys find it useful.
Ya know, I just spent the past two days teaching myself RoR from
scratch. I'd gotten about 3/4 of the functionality you have (with
none of the style) and this comes out. Thanks a ton! Now I can get
back to doing the application work, and stop dorking around with the
interface so much!

RoR just went from RAD to k-RAD. Thanks a ton!
Richard W. (Guest)
on 2006-02-27 03:57
David Olbersen wrote:
> On Feb 25, 2006, at 1:36 PM, Richard W. wrote:
>
>>
>> http://www.height1percent.com/articles/2006/02/21/...
>> scaffold-generator
>> Its a generates a much better starting point for an Ajax'ified
>> application or for any application than the existing scaffold
>> generator. I hope you guys find it useful.
> Ya know, I just spent the past two days teaching myself RoR from
> scratch. I'd gotten about 3/4 of the functionality you have (with
> none of the style) and this comes out. Thanks a ton! Now I can get
> back to doing the application work, and stop dorking around with the
> interface so much!
>
> RoR just went from RAD to k-RAD. Thanks a ton!

Thanks for the kind words everyone. If you found the scaffold at all
useful or interesting please drop by the lastest post on my blog and
opon on what you'd like to see built/fixed next. Thanks again.

http://www.height1percent.com/articles/2006/02/26/...

Rich
kevin (Guest)
on 2006-02-27 15:46
Leon L. wrote:
> kool... but paging support would be excellent!
To get pagination, I added these lines to view_list.rhtml, right after
the table.

<div align=right>
<%%= link_to '<<', { :page => @pages.current.previous } if
@pages.current.previous %>
<%%=pagination_links_each(@pages, :window_size => 4) do |n|
    "<a href='?page=#{n}'>#{n}</a>"; end %>
<%%= link_to '>>', { :page => @pages.current.next } if
@pages.current.next %>
</div>

AND replaced the first 20 lines in controller.rb

class <%= controller_class_name %>Controller < ApplicationController

<% unless suffix -%>
  def index
    list
    render_action 'list'
  end
<% end -%>


<% for action in unscaffolded_actions -%>
  def <%= action %><%= suffix %>
  end
<% end -%>

  def list<%= suffix %>
    #@<%= plural_name %> = <%= model_name %>.find :all
    #render :layout => false
	@pages, @<%= plural_name %>  = paginate :<%= plural_name %> , :per_page
=> 10
  end
Richard W. (Guest)
on 2006-02-27 17:13
kevin wrote:
> Leon L. wrote:
>> kool... but paging support would be excellent!
> To get pagination, I added these lines to view_list.rhtml, right after
> the table.
>
> <div align=right>
> <%%= link_to '<<', { :page => @pages.current.previous } if
> @pages.current.previous %>
> <%%=pagination_links_each(@pages, :window_size => 4) do |n|
>     "<a href='?page=#{n}'>#{n}</a>"; end %>
> <%%= link_to '>>', { :page => @pages.current.next } if
> @pages.current.next %>
> </div>
>
> AND replaced the first 20 lines in controller.rb
>
> class <%= controller_class_name %>Controller < ApplicationController
>
> <% unless suffix -%>
>   def index
>     list
>     render_action 'list'
>   end
> <% end -%>
>
>
> <% for action in unscaffolded_actions -%>
>   def <%= action %><%= suffix %>
>   end
> <% end -%>
>
>   def list<%= suffix %>
>     #@<%= plural_name %> = <%= model_name %>.find :all
>     #render :layout => false
> 	@pages, @<%= plural_name %>  = paginate :<%= plural_name %> , :per_page
> => 10
>   end

Yep, you could do that if you really need pagination at this point. A
better solution would involve one where pagination would work more
client side. For example if you deleted 3 rows on the table it should
pull up 3 from the next page instead of just having a shrinking page and
inconsistent data when you go to the next.

We'll support that eventually, and sooner than later.

Rich
Doug B. (Guest)
on 2006-02-27 17:59
(Received via mailing list)
This is superb.  Thank you so much for your contribution!!

One point though - I may be missing something obvious but when I create
the
following scaffold using a module:

ruby script/generate scaffold ajax_scaffold Tariff 'admin/tariffs'

When clicking to 'Create New' it has a routing error stating it can't
find:
admin/admin/tariff/new

I go into the code and find all the links and controllers are relative
"admin/tariff" I can solve the issue by one of two ways:
1) Add a forward slash before admin "/admin/tariff"
2) remove the "admin/" so the relative path is correct.

Not a worry as I have it working but just thoguht I'd let you know.

All the best - Keep up the good work!!

Doug
Conrad T. (Guest)
on 2006-02-28 21:02
(Received via mailing list)
Hi, coudl someone tell me what to down load and how to install it?

Thanks in advance,

-Conrad
Greg D. (Guest)
on 2006-02-28 21:26
(Received via mailing list)
On 2/28/06, Conrad T. <removed_email_address@domain.invalid> wrote:
> Hi, coudl someone tell me what to down load and how to install it?

It's right there on the page:

Look for "Getting Started"

http://www.height1percent.com/articles/2006/02/21/...





--
Greg D.
Zend Certified Engineer
MySQL Core Certification
http://destiney.com/
Conrad T. (Guest)
on 2006-02-28 21:36
(Received via mailing list)
Hi, when I go to the download area, I'm presented with three files for
the 2.1.0 release. Two of the files are compressed archives and one of
them is a .gem file.  It's simply not clear as to what to download and
it seem that some steps were skipped to me.

-Conrad
James B. (Guest)
on 2006-02-28 22:18
Conrad T. wrote:
> Hi, when I go to the download area, I'm presented with three files for
> the 2.1.0 release. Two of the files are compressed archives and one of
> them is a .gem file.  It's simply not clear as to what to download and
> it seem that some steps were skipped to me.
>
> -Conrad

The easiset thing to do is to first install gem, which effectively is
Ruby's package manager.  Get gem from rubyforge :

http://rubyforge.org/frs/?group_id=126&release_id=2471

and unpack it into a working directory.

From the package directions:

If you don't have any gems install, there is still the pre-gem
approach to getting software ... doing it manually:

1. DOWNLOAD FROM: http://rubyforge.org/frs/?group_id=126
2. UNPACK INTO A DIRECTORY AND CD THERE
3. INSTALL WITH:  ruby setup.rb all  (you may need admin/root privilege)

Now you can do things like:

# gem install ajax_scaffold_generator --remote

and everything needed for ajax_scaffold_generator will be identified and
downloaded for you (after you consent).

Installing gem now will make extending and maintaining ruby and rails
much easier for you later.

Regards,
Jim
Adam F. (Guest)
on 2006-02-28 22:31
(Received via mailing list)
On Tue, Feb 28, 2006 at 09:18:44PM +0100, James B. wrote:
[...]
> # gem install ajax_scaffold_generator --remote
>
> and everything needed for ajax_scaffold_generator will be identified and
> downloaded for you (after you consent).
>
> Installing gem now will make extending and maintaining ruby and rails
> much easier for you later.

It occurs to me after using a bunch of these - why are the rails gems
not labeled as such?

There are lots of gems, and many of them are generic ruby
packages. Perhaps we could encourage people who make gems for rails to
specify that they're rails-specific in the names.

It would be much clearer if this was rails_ajax_scaffold_generator.


--
				- Adam

** Expert Technical Project and Business Management
**** System Performance Analysis and Architecture
****** [ http://www.everylastounce.com ]

[ http://www.aquick.org/blog ] ............ Blog
[ http://www.adamfields.com/resume.html ].. Experience
[ http://www.flickr.com/photos/fields ] ... Photos
[ http://www.aquicki.com/wiki ].............Wiki
[ http://del.icio.us/fields ] ............. Links
Joe Van D. (Guest)
on 2006-02-28 23:04
(Received via mailing list)
On 2/26/06, Richard W. <removed_email_address@domain.invalid> wrote:
> > scratch. I'd gotten about 3/4 of the functionality you have (with
> http://www.height1percent.com/articles/2006/02/26/...
>

How could I modify this to do file uploads?  I can't do uploads inside
form_remote_tag, right?
Richard W. (Guest)
on 2006-03-01 05:40
Doug: Thanks for pointing that out. Honestly, I hadn't done much with
the original scaffold generator outside of having a different controller
name than the model name. I will add this into my test scenarios and
hopefully release a minor point release to cover this issue. Thanks
again for bringing it to my attention.

Doug B. wrote:
> This is superb.  Thank you so much for your contribution!!
>
> One point though - I may be missing something obvious but when I create
> the
> following scaffold using a module:
>
> ruby script/generate scaffold ajax_scaffold Tariff 'admin/tariffs'
>
> When clicking to 'Create New' it has a routing error stating it can't
> find:
> admin/admin/tariff/new
>
> I go into the code and find all the links and controllers are relative
> "admin/tariff" I can solve the issue by one of two ways:
> 1) Add a forward slash before admin "/admin/tariff"
> 2) remove the "admin/" so the relative path is correct.
>
> Not a worry as I have it working but just thoguht I'd let you know.
>
> All the best - Keep up the good work!!
>
> Doug
Richard W. (Guest)
on 2006-03-01 05:41
Or even 'ajax_scaffold_rails_generator' .. but nevertheless you make a
very valid point. I wish I had thought of that before I created all the
packages (I know I could go back and change them, but I don't really
wanna deal with the confusion that would cause).

Adam F. wrote:
> On Tue, Feb 28, 2006 at 09:18:44PM +0100, James B. wrote:
> [...]
>> # gem install ajax_scaffold_generator --remote
>>
>> and everything needed for ajax_scaffold_generator will be identified and
>> downloaded for you (after you consent).
>>
>> Installing gem now will make extending and maintaining ruby and rails
>> much easier for you later.
>
> It occurs to me after using a bunch of these - why are the rails gems
> not labeled as such?
>
> There are lots of gems, and many of them are generic ruby
> packages. Perhaps we could encourage people who make gems for rails to
> specify that they're rails-specific in the names.
>
> It would be much clearer if this was rails_ajax_scaffold_generator.
>
>
> --
> 				- Adam
>
> ** Expert Technical Project and Business Management
> **** System Performance Analysis and Architecture
> ****** [ http://www.everylastounce.com ]
>
> [ http://www.aquick.org/blog ] ............ Blog
> [ http://www.adamfields.com/resume.html ].. Experience
> [ http://www.flickr.com/photos/fields ] ... Photos
> [ http://www.aquicki.com/wiki ].............Wiki
> [ http://del.icio.us/fields ] ............. Links
Richard W. (Guest)
on 2006-03-01 05:46
I'm not honestly sure about whether file uploads work inside a
form_remote_tag. If they don't then obviously an ajax scaffold won't
help you one bit.

If you can then you should be able to create a simple file manager
easily with by creating a basic scaffold (maybe of an UploadFile model
that has a label attribute), modifying the form to add a file upload box
and creating the necessary controller code to handle form submission of
said file upload.

Joe Van D. wrote:
> On 2/26/06, Richard W. <removed_email_address@domain.invalid> wrote:
>> > scratch. I'd gotten about 3/4 of the functionality you have (with
>> http://www.height1percent.com/articles/2006/02/26/...
>>
>
> How could I modify this to do file uploads?  I can't do uploads inside
> form_remote_tag, right?
Jeff McDonald (Guest)
on 2006-03-01 10:15
(Received via mailing list)
Yep, JavaScript doesn't have access to the filesystem (unless you're
Microsoft).  So form_remote_tag will not work for file uploads.

-- Jeff

(here's one reason why)
http://www.symantec.com/avcenter/venc/data/removed...
Roberto S. (Guest)
on 2006-03-01 17:54
(Received via mailing list)
well, with Kyle's plugin ( http://www.kylemaxwell.com/ ) you CAN upload
files from form_remote_tag. Check out the sample app and the comments
for
how to make it work on rails edge
Helmut Sedding (Guest)
on 2006-03-01 18:03
(Received via mailing list)
Hi Richard,

please keep an eye on cross-browser-compatibility.

What is with non-javascript-browsers like dillo or links? Do you
provide alternative ways for a use case?

Does it work with upcoming browsers that are not yet released or even
thought of?

regards,
Helmut

Am 25.02.2006 um 22:36 schrieb Richard W.:
Richard W. (Guest)
on 2006-03-01 22:46
It only supports and probably only will support FF 1.0+, Safari 10.4+
and IE 6+. I have a post on my site about future direction and I
specifically state that I will *NOT* spend my time making it work for
the ~1% of people that don't have one of those browsers I just listed.

Same goes for anyone without JS. I mentioned this on that same blog post
that I am not interested in devoting a large amount of time to people
stuck in the stone age with Javascript. They make up a very small % of
the population and I'm not that concerned with them. If you are building
an Ajax application and your core set of users don't have JS then you
are doing something wrong.

As far as 'upcoming browsers that are not yet released or even thought
of' I'm not sure if that's a joke or if you are using that as a segway
to sell me a crystal ball :) But no, I won't guarantee that I can
support indeterminate things in the future hehe.

Rich


Helmut Sedding wrote:
> Hi Richard,
>
> please keep an eye on cross-browser-compatibility.
>
> What is with non-javascript-browsers like dillo or links? Do you
> provide alternative ways for a use case?
>
> Does it work with upcoming browsers that are not yet released or even
> thought of?
>
> regards,
> Helmut
>
> Am 25.02.2006 um 22:36 schrieb Richard W.:
Conrad T. (Guest)
on 2006-03-04 09:52
(Received via mailing list)
Hi Richard, when I one clicks the "create new", it creates a form for
taking user inputs.  However, shouldn't one only be able to create a
single form?  For example, when I click create, it can generate one
form right after the previous on the same page.  I'm guessing that it
should only be one form presented and the form should be presented
only when it's not visible.

-Conrad
Richard W. (Guest)
on 2006-03-05 01:18
Conrad T. wrote:
> Hi Richard, when I one clicks the "create new", it creates a form for
> taking user inputs.  However, shouldn't one only be able to create a
> single form?  For example, when I click create, it can generate one
> form right after the previous on the same page.  I'm guessing that it
> should only be one form presented and the form should be presented
> only when it's not visible.
>
> -Conrad

Why limit it? I don't see any reason to restrict the user to only have
one create form open at once. If you know of a reason that I haven't
thought of let me know.

-Rich
Justin F. (Guest)
on 2006-03-05 03:17
(Received via mailing list)
Richard W. wrote:

> are doing something wrong.
The most important consideration here is that disabled people (who may
rely on assistive technologies like screen readers) may not be able to
use a site which depends on JavaScript and DHTML. It's fine to give a
better user experience to people who can see well and use a mouse, but
it's not fine (and may be illegal) to prevent less fortunate people from
using a web site or application.

   Justin
Richard W. (Guest)
on 2006-03-05 03:31
Justin F. wrote:
> Richard W. wrote:
>
>> are doing something wrong.
> The most important consideration here is that disabled people (who may
> rely on assistive technologies like screen readers) may not be able to
> use a site which depends on JavaScript and DHTML. It's fine to give a
> better user experience to people who can see well and use a mouse, but
> it's not fine (and may be illegal) to prevent less fortunate people from
> using a web site or application.
>
>    Justin

Justin, I laugh at the idea but you do put a more human face on the
problem. I apologize for being so crass in my comments.

Thankfully thats all water under the bridge now, as the 2.2.0 release
gracefully degrades in the abscence of Javascript.

Rich
Justin F. (Guest)
on 2006-03-05 04:48
(Received via mailing list)
Richard W. wrote:
>>
>>    Justin
>
> Justin, I laugh at the idea but you do put a more human face on the
> problem. I apologize for being so crass in my comments.
>
> Thankfully thats all water under the bridge now, as the 2.2.0 release
> gracefully degrades in the abscence of Javascript.

Well done! I appreciate that scaffold is only to get people started, but
it's also a way of teaching by example...

I was impressed by the demo of your first version, and will take another
look.

   Justin
Erik B. Ordway (Guest)
on 2006-03-29 23:59
(Received via mailing list)
I love the Ajax scaffold generator for machine administrative
consoles.  I do have a suggestion though.


A suggestion for the generator.  With some hacking it is possible to
support putting one thing in a sub list of the list for an other
thing.  Say that you have a display for a set of vending machines and
for each vending maching there are n different things sold so the
list display for vending machines might look like:

Vending machines----------------------------Create vending machine
Vending machine #1                               Edit , Delete
       Sales Items------------------------------------Create new
sales item
        Item #1                 400 in stock         Edit , Delete
        Item #2                 12 in stock            Edit , Delete
        ......
Vending machine #2                               Edit , Delete
       Sales Items------------------------------------Create new
sales item
        Item #1                 53 in stock         Edit , Delete
        Item #4                 370 in stock        Edit , Delete
        ......

If the type of Vending machine = vender and Sales items = item the
change need to do this is to modify the value used by the javascript
in 'ajax_scaffold.js' to find the right DOM elements.  What I did was
add an '_#{vender_id} to each place an id was being set or
'link_to_remote was being set.  This modified the value used as
'type' in 'ajax_scaffold.js' .  Also the 'list.rhtml' for item was
turned in to a partial '_list.rhtml'  so that it could be called from
the '_vendor.rhtml' partial

To make this easier it would be great if the *.rhtml templates took a
value set (:parent_id for example) in :locals of the call to the
partial that insert a value to all the css id names and
call_to_remote calls  to do what I did manually to each place the
'type' value was set.  This could look like the following

What is now
	<h2>Sales Items</h2>
<div class="actions">
	<%= loading_indicator_tag 'item', "new" %>
	<%= link_to_remote "Create New",
         { :url => { :controller => 'items', :action => 'new'  },
         	:loading => "AjaxScaffold.newOnLoading(request,'items');",
		:success => "AjaxScaffold.newOnSuccess(request,'items');",
		:failure => "AjaxScaffold.newOnFailure(request,'items');" },
         { :href => url_for(:controller => 'items', :action => 'new'  ),
		:class => "create" } %>


What I did
	<h2>Sales Items</h2>
<div class="actions">
	<%= loading_indicator_tag 'item_'+vender_id.to_s, "new" %>
	<%= link_to_remote "Create New",
         { :url => { :controller => 'items', :action =>
'new' , :vender_id=>vender_id },
         	:loading => "AjaxScaffold.newOnLoading(request,'items_#
{vender_id.to_s}');",
		:success => "AjaxScaffold.newOnSuccess(request,'items_#
{vender_id.to_s}');",
		:failure => "AjaxScaffold.newOnFailure(request,'items_#
{vender_id.to_s}');" },
         { :href => url_for(:controller => 'items', :action =>
'new' , : vender_id => vender_id ),
		:class => "create" } %>

WHAT COULD BE

	<h2>Sales Items</h2>
<div class="actions">
	<%= loading_indicator_tag 'item_'+parent_id, "new" %>
	<%= link_to_remote "Create New",
         { :url => { :controller => 'items', :action =>
'new' , :parent_id=>parent_id },
         	:loading => "AjaxScaffold.newOnLoading(request,'items_#
{parent_id}');",
		:success => "AjaxScaffold.newOnSuccess(request,'items_#
{parent_id}');",
		:failure => "AjaxScaffold.newOnFailure(request,'items_#
{parent_id}');" },
         { :href => url_for(:controller => 'items', :action =>
'new' , :parent_id => parent_id ),
		:class => "create" } %>
This topic is locked and can not be replied to.