*How* to design a simple app for Rails


#1

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


#2

On 12/13/05, Ed W removed_email_address@domain.invalid 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 L.
removed_email_address@domain.invalid
http://AllTom.com/


#3

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


#4

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. :wink:

Mike P.


#5

On Dec 18, 2005, at 6:59 PM, Mike P. 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>


#6

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…