Forum: Ruby on Rails *How* to design a simple app for Rails

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.
443a308e12ba2a3082fb6170ca94c2ef?d=identicon&s=25 Ed Wg (ewildgoose)
on 2005-12-13 12:55
(Received via mailing list)
Like many people I am trying to experimenting with writing new apps in
Rails and having some teething problems getting my head around how they
should be structured to take best advantage for Rails.  It's a question
of how to *structure* the app once you go more complicated than those
easy "Todo list" examples (and I do own the Agile books)

To illustrate some of the things I am a little unsure about here is a
tiny example app: store made up of products which are in categories.
Each product has a price and description.  Clearly we have model objects
for Category and Product

OK, so I start out:

- Controller called StoreController which has two methods
"list_categories" (takes no params) and "list_products" which takes a
param of category_id and lists all the products in that category with a
pager
- Views: list_categories is the obvious list of categories and clicking
on a category takes you to "store/list_products/xxx".  list_products has
the obvious list of stuff, but also has:
----> a search box which would refine the list to matching items,
----> and a toggle link titled "show descriptions" which changes the
list from a plain list of items to a list with some description of each
item (ie extra stuff)


OK, so this is where I start to wonder how to "rails"ify it.  Simple
thing like the toggle link - should this be directed to some new method
in the controller which toggles some session variable on or off and then
trying to redirect back to the original URL.  Or do we just (via the
link_to method) append a "?show_descriptions=1" to the current URL and
reload?

How to handle the search in the same screen.  Should this redirect back
to the same page with a "?search_product=xxx" param appended?  Is the
rails way to have another method in the controller that will have
cleaner URLs...?  Since this page now looks very like our global search
page (that we probably also want) then perhaps the url should change to
reflect that?  (Note: This is a question about how to structure URLs
rather than a question about coding this hypothetical app)

What happens if the user goes to "/store/list_products" with no
parameter (assuming it doesn't make sense for the app to list every
product in every category)?  I guess in this app it makes sense to
*redirect* to list_categories (perhaps with some help message)?

I would then like to Ajax enable the search and toggle button BUT it is
very important that the app still be usable with Links.  How would you
go about making sure that app remains usable in text-only browsers (and
for people with javascript off)?  Would this have any impact on how you
designed the views and controller in order to divide up the code and
make it reusable?


Grateful for any thoughts on how *you* would structure this little app.
If the questions seem a little dumb, please realise that the app is just
a quick hypothetical playground - I hope the underlying question is
sensible though.

Thanks

Ed W
7a28bf7b0932a9486c21f1a33eb431ba?d=identicon&s=25 Tom Lieber (Guest)
on 2005-12-18 19:05
(Received via mailing list)
On 12/13/05, Ed W <lists@wildgooses.com> wrote:
> Like many people I am trying to experimenting with writing new apps in
> Rails and having some teething problems getting my head around how they
> should be structured to take best advantage for Rails.  It's a question
> of how to *structure* the app once you go more complicated than those
> easy "Todo list" examples (and I do own the Agile books)

Have you gotten help with these questions yet?

> Thanks
>
> Ed W

Sincerely,

Tom Lieber
tom@alltom.com
http://AllTom.com/
7f75a9ab7ef058b2e7aafa89bc20eea2?d=identicon&s=25 Chris Grant (Guest)
on 2005-12-18 20:11
(Received via mailing list)
Ed / Tom,

I am having the same difficulties.

I have coded PHP for a few years and various other languages.  I love
the idea of Rails and have purchased the Agile book and the PickAxe.  I
was so enthused about Rails that I read the Agile book in a couple of
days.  The walk-through application presents a lot of useful information
but, I feel, that the authors should have presented the non-scaffolding
approach to beginning a project in later chapters.  What is really
needed is for someone to write a book that walks through the development
of a larger-scale application.  I've been contemplating going to one of
the Rails seminars that walks through the development of BaseCamp but
that's quite a bit of moolah.

Now, I know that I will need to learn Ruby to take full advantage of
everything that Rails has to offer and I've been devoting most of my
time to that task.  I've read the Rails wiki and numerous tutorials,
watched the videos and read numerous blogs.  I know that a lot of books
are in the works and hopefully one of these books will address the
real-world approach to developing a larger-scale application with Rails.

Am I alone in this confusion about the best starting place for a big
application?

-Chris
55742d912a9003080d202c5522d4de00?d=identicon&s=25 Ken Bowley (Guest)
on 2005-12-18 20:56
(Received via mailing list)
I've been using Ruby for a few years now (our company built a decent
sized
web application for a customer before rails ever came out), but I've
just
recently started to work with Rails.  Even I had trouble getting my head
around Rails when I first looked at it (many months ago).  The way I
finally jumped over that small learning curve was to just start writting
something.  Following the 'todo' application tutorial didn't really
teach
me anything.  It's when I started writting my own application (simple
blog
with Blogger and MetaWeblog api's, and a utility to track milage for my
motorcycle) that it finally clicked.  And once you have something
working,
make sure you write tests for everything... then refactor everything
using
the knowledge you've gained.

No tutorial is going to teach you what you'll need in order to write a
large scale application.  Actually writting something, and (more
importantly) writting tests for it, will teach you what you need to
know.

Ken...
5c6727e573b7be20dea6a6880856a888?d=identicon&s=25 Mike Pence (Guest)
on 2005-12-19 00:59
(Received via mailing list)
It is a long fall from the scaffolding into real world apps. Your best
bet is to just dive right in and use the #rubyonrails IRC group for
support. We're nice there, cause you know, Matz is nice.

Matz is the true programmer and DHH is his prophet. ;-)

Mike Pence
9b995363bb34f302bdd7705b8490e07a?d=identicon&s=25 Scott Phelps (Guest)
on 2005-12-19 02:02
(Received via mailing list)
On Dec 18, 2005, at 6:59 PM, Mike Pence wrote:

> It is a long fall from the scaffolding into real world apps. Your best
> bet is to just dive right in and use the #rubyonrails IRC group for
> support. We're nice there, cause you know, Matz is nice.

I have to second that sentiment.  Our community is phenomenal!

>>> enthused about Rails that I read the Agile book in a couple of
>>> walks through the development of BaseCamp but that's quite a bit
>>> approach to
>>> developing a larger-scale application with Rails.
>>>
>>> Am I alone in this confusion about the best starting place for a big
>>> application?

Ruby was ahead of it's time when it came out.  I think maybe it still
is.  There are still a lot of sideline critics out there.  I think
that this is the result of the fact that outside of the tutorials and
scaffolding there are concepts in our world that take some mental
effort to wrap your head around.  MOst people are just not willing to
spend two days "figuring it out." For me it's because Ruby (and thus
Rails) forces you to think different.  With concepts like Mixins and
code blocks I feel compelled to code more elegantly and  expressively.

The PickAxe Book is my best friend.  I use it a lot more than the
Agile Web Dev book.  Actually, I refer more to the RoR API than
anything for how to do something in Rails.  The DevBoi Firefox plugin
is invaluable.

So, I would suggest study the PickAxe book, lean heavy on the RoR
API, and when you get stuck come and join us at #rubyonrails.


Ciao!
-
Scott aka <unix_cat>
This topic is locked and can not be replied to.