No, its not.
Unless you are _just_ dong a CRUD.
Anything with more complex actions (a wiki: search, attach, roll-back,
access control ...; a game: many functions!) you ARE going to have to
specify the actions and quite possibly the controller.
The benefits of Rest are far from clear.
Or perhaps I should say they are far from being stated well and clearly
and in a form that allows them to be applied situations beyond the basic
CRUD.
No doubt there are, to quote a famous novel and movie "minds superior to
(this) man's" that can and do use REST in more general situations.
Perhaps they could explain it to us duffers and newbies, then.
But to date, for all my drilling down ("google is you .. if not friend
then a least ally"), I find a lot of "its great stuff" from people who
have simplified applications but very little details of the "HOW".
--
The state can't give you free speech, and the state can't take it away.
You're born with it, like your eyes, like your ears. Freedom is
something you assume, then you wait for someone to try to take it away.
The degree to which you resist is the degree to which you are free...
--Utah Phillips
map.resources :topics, :collection => {:search => :get} ). In my months of learning to do a more RESTful site, I've found out that it's not about making a web-service-like website, but more of what thinking RESTfully does to your design.
In short, RESTful web design is cleaner and much easier to understand. It keeps your controllers small and the logic seperated out. So instead of one massive WikiController, you'd have a WikiController, TopicController, AccountController, etc, which is much easier on: future developers of the product, people trying to bookmark parts of the wiki, the webserver for not having to deal with so much code at once, etc. It's just a good idea.
Give it a try, you'll see what I mean.
Jason
--
Amos King
A. King Software Development and Consulting, L.C.
http://dirtyInformation.com
--
Looking for something to do? Visit http://ImThere.com
While that's plausible, I still don't see how it makes sense. Please see
may later reply to Jason. I don't see what advantage this has over
putting the search code in 'lib/search.rb'.
--
"Current economics is merely refining the obsolete. Economic theory is
still based on the scarcity axiom, which doesn't apply to information.
When I sell you a phone, I no longer have it. When I sell information
to you, I have more information by the very fact that you have it and I
know you have it. That's not even true of money."
-- Peter Drucker, WiReD6.03 Mar-1998
I have and I don't.
Obviously I "don't get it".
I've plugged "restful authentication" into my wiki and that's fine
because its compartmentalized, but the rest of the wiki works entirely
on urls of the form
http://hostname.com/Webname/TopicName
with an optional "/:action" - edit, history ... you know the rest
(sorry, I can't resists puns)
Intrinsically there ARE methods. Strictly speaking there isn't even
CRUD, since editing a previously non existent topic causes its creation
and you don't 'delete' a topic you 'rename' it to the waste-bin Web.
So there's WikiController and no TopicController or WebController. (Oh,
there was when experimenting and as an admin interface, but they are
long gone, their function wasn't relevant to the wiki interface.)
The authentication function is completely orthogonal to the Wiki space
so having '/login' and '/register' is not an issue.
You say "RESTful web design is cleaner and much easier to understand"
but I don't see that. So many people say that and its getting to sound
like a "fashion" and "proof by assertion". As I've said, there are blog
postings where people claim this simplification by don't show the 'how'
and don't show it in a way that I can learn from the process.
Now and in the past I'm thinking in terms of what the application looks
like to the user. Navigating the wiki, the wiki's functionality is one
thing and the 'login/registration' is a "popup" (if only I could get
popups to work the way I want) in the workflow (aka "You need to login
to access this topic" type popups). This has led me to think in terms
of the routing and the mapping of the actions, of which there are many
beyond CRUD.
So, even if I somehow REST-ificate the WikiController, how do I decide
what GET/PUT are 'history', 'alter metadata', 'diff r1=n, r2=m', rename,
'search', 'upload', 'view attachment' and so on.
Please, I'm seeking a methodology and approach. I'd love to have a
simpler WikiController. I'd love to have a UiController that handles
the commonality of access control, dealing with exceptions and so on
(right now its 'lib/ui_wrapper.rb) that 'view', 'edit' and so on are
parameters for (modules?). But what value of WebController or
TopicController? (All I can see for them is web services to give lists
for 'rename'.)
I'm sorry, Jason, without some explanation it all seems like "proof by
assertion" or "the latest fashion" to me.
I'm finding this very frustrating since I can't see how this is relevant
to me without a lot of jigging the routing, like you illustrate, Jason.
At which point I say "Why bother? How is this different from what I'm
doing now with all the methods?"
--
Do you want the truth, or a well-designed machination brought
into existence solely for the stroking of your ego?
-- Empty <em...@theriver.com> on alt.goth
??
And why not have separate controllers for 'edit' and 'tag' and 'attach'
and view' and ...
Sorry. I don't see it.
--
Never forget: The road to Hell is paved with good intentions.
So tread hard on good intentions. -- rjd4
REST allows you to have a conventional layout to your controllers,
expose web services easily, get nice named routes in Rails (including
for your custom methods), and because of its conventional layout, you
can abstract it very easily (e.g., make_resourceful reduces the CRUD
portion of your controllers to 4 lines rather than 100).
If you're concerned about your URLs, then customize the routing.
There's nothing saying you can't have routing aliases for browser
clients of your RESTful actions so long as the RESTful one is still
available for web services.
--Jeremy
--
http://www.jeremymcanally.com/
My books:
Ruby in Practice
http://www.manning.com/mcanally/
My free Ruby e-book
http://www.humblelittlerubybook.com/
My blogs:
http://www.mrneighborly.com/
http://www.rubyinpractice.com/
OK, so back to my wiki. The 'edit' is the only thing there, nothing
destructive.
> REST allows you to have a conventional layout to your controllers,
You don't mean '/views/layouts'? So what does 'conventional' mean in
this context? (more below)
> expose web services easily,
What if I don't HAVE them? Why bother?
> get nice named routes in Rails (including for your custom methods),
Let me try again: I don't WANT what I've seen as nicely named routes
I don't WANT URLs like
http://example.com/web/Webname/topic/TopicName
or 'id' instead of 'name'
As I said, apart from out-of-ban things like login its just
http://example.com/Webname/TopicName[?params]
> and because of its conventional layout, you
> can abstract it very easily (e.g., make_resourceful reduces the CRUD
> portion of your controllers to 4 lines rather than 100).
But I don't see what I'm trying to address as 'conventional CRUD'.
As I said at the beginning, I understand RESTfulnesss for that
invoice-item type, CRUD type applications, but there are a lot of web
based things that don't follow that model. Wikis and games being a few.
> If you're concerned about your URLs, then customize the routing.
I am. And its very simple. Just one line. (see above)
> There's nothing saying you can't have routing aliases for browser
> clients of your RESTful actions so long as the RESTful one is still
> available for web services.
Amos King suggested what seems to be mapping each method onto a
controller. That doesn't make sense to me either.
I can understand a Search Controller in the context of a page with a
form for the search parameters then submitted to that controller, but
its still drawing on the basic wiki functionality for rendering, so why
bother.
If a search is embedded in a page (see TWiki, Xwiki, MoinMoin and many
other wikis) then I can't see it being a web service instead of a
library utility. The Search Page calls this library too. So why bother
with the controller to move the code out of the WikiController?
If I have a search controller to move the search code out of the
WikiController (where it wasn't in the first place 'cos it was in a
library) the its only going to have one method.
So why, reductio ad absurdem, don't I convert everything that is a
method in the WikiController into a controller with one method, get rid
of the WikiController and do everything from
'app/controllers/Application.rb' ?
Let me ask all this another way.
I've asked this before in another wording and got no reply.
The user tries to 'view' a page. The WikiController's 'view' method
gets to the point where it finds the topic and checks accessibility.
Right now if a login is required to view that page it does a redirect
with return-to to the login page. Its irrelevant whether the login
mechanism is RESTful or not. I've installed 'restful authentication'
and its happy with the redirect & return-to, as was the old acts_as ..
with no RESTful-ness. So what's the benefit?
Please don't say 'extending functionality'. I pasted in code to do p/w
change into both versions of the authenticator with ease.
Can I do some magic pop-up with 'restful authentication' that I couldn't
with the old version? I've asked about that as well and again got no
reply. Wouldn't a popup authenticator be a 'web service' of some kind?
--
"I think there is a world market for about five computers."
Thomas J. Watson, chairman of the board of IBM, 1943
Just an observation: you seem really confrontational about REST.
That's going to make it hard to get people to answer you.
But, here's my take on it.
Following the RESTful patterns gives you immediate benefits and long-
term benefits.
Immediate benefits:
- Web services for basically free
- Cleaner controllers, although possibly more of them
- Easier maintenance for future developers, because of following
the conventions
Long-term benefits:
- By thinking in terms of resources, you end up composing your
application differently. Lots of people have found, through
real experience,
that this "different" is better, for them.
- ^^ this gets more and more obvious over time.
The reason you're getting lots of "try it, you'll like it" is because
this isn't an obvious "X is better than Y because Z". It's more,
"Man, I did Y, and I really felt like things went better than when I
did X."
If you want to honestly find out more about the experiences of people
who have used RESTful patterns and found value from them, I'm more
than happy to go into more detail.
OK, so it's a GET request. A web service usually won't ever call edit
because it doesn't need a form; it will submit XML representations
straight to create/update.
>
> You don't mean '/views/layouts'? So what does 'conventional' mean in
> this context? (more below)
>
No, I don't.
>
> Let me try again: I don't WANT what I've seen as nicely named routes
> I don't WANT URLs like
>
> http://example.com/web/Webname/topic/TopicName
> or 'id' instead of 'name'
>
> As I said, apart from out-of-ban things like login its just
>
> http://example.com/Webname/TopicName[?params]
>
>
I don't mean on the front end; I mean things like `wiki_entry_path` or
`edit_user_path`. It makes your code MUCH cleaner.
> But I don't see what I'm trying to address as 'conventional CRUD'.
> As I said at the beginning, I understand RESTfulnesss for that
> invoice-item type, CRUD type applications, but there are a lot of web
> based things that don't follow that model. Wikis and games being a few.
>
Right, but if you have resources (e.g., entries, pages, users), then
you can use it. No one is forcing you to use it. It's just an
easier, cleaner way to structure your application.
>
> I am. And its very simple. Just one line. (see above)
>
OK, keep that line. Problem solved.
>
> Amos King suggested what seems to be mapping each method onto a
> controller. That doesn't make sense to me either.
>
> I can understand a Search Controller in the context of a page with a
> form for the search parameters then submitted to that controller, but
> its still drawing on the basic wiki functionality for rendering, so why
> bother.
>
> If a search is embedded in a page (see TWiki, Xwiki, MoinMoin and many
> other wikis) then I can't see it being a web service instead of a
> library utility. The Search Page calls this library too. So why bother
> with the controller to move the code out of the WikiController?
>
You don't have to. You can have a search method on WikiController.
Nothing is stopping you.
> Let me ask all this another way.
> I've asked this before in another wording and got no reply.
>
> The user tries to 'view' a page. The WikiController's 'view' method
> gets to the point where it finds the topic and checks accessibility.
> Right now if a login is required to view that page it does a redirect
> with return-to to the login page. Its irrelevant whether the login
> mechanism is RESTful or not. I've installed 'restful authentication'
> and its happy with the redirect & return-to, as was the old acts_as ..
> with no RESTful-ness. So what's the benefit?
>
> Please don't say 'extending functionality'. I pasted in code to do p/w
> change into both versions of the authenticator with ease.
>
> Can I do some magic pop-up with 'restful authentication' that I couldn't
> with the old version? I've asked about that as well and again got no
> reply. Wouldn't a popup authenticator be a 'web service' of some kind?
>
You're completely missing the point of REST. I'm not even sure what
you're asking there. The benefit of REStful Authentication is that
clients that aren't web browsers can create a session and access
resources just like a browser. The point is extending functionality
or something. It's giving things a structure that is consistent and
accessible by clients without a lot of overhead and complicated API.
ActiveResource is one such client. If I'm making a remote client to
your wiki, I will need to create an ActiveResource model for Session,
Entry, and so on. When I try to access an Entry that I don't have
permission for, your app will throw me a permission denied error.
Then my app will know to create a Session (through REST, mind you, so
using POST to create with the right params) and then continue on with
what it was doing. If this was a random RPC interface, I'd have all
kinds of socket madness going on and parsing of XML by hand and so on.
If you're not convinced by now, then perhaps you need to read a book
or article or just not worry about it. REST may offer no benefit to
you.
--Jeremy
Maybe it's just because I'm used to it now or something.
--Jeremy
--
Thank you so much, Mark.
You've expressed a few points that I've omitted.
--
If God had intended Man to Watch TV, He would have given him Rabbit Ears.
OK, but HOW?
--
Skill without imagination is craftsmanship and gives us many useful
objects such as wickerwork picnic baskets. Imagination without skill
gives us modern art.
-- Tom Stoppard
'Named routes'?
Surely you don't need RESTful design for that.
I have named routes anyway.
--
If the errors of the past were good enough for
our ancestors, they re good enough for us!
I'm sorry if I seem confrontational; I'm just frustrated on a number of
counts.
Over the past months I've asked more specific questions that are related
to this and not got any answers. None.
And as I say, I see plenty of "isn't it great" postings in blogs but
very little that actually explains how to transform anything beyond a CRUD.
And it all seems to be coming out at once.
Surely I can't be the only person so afflicted?
--
It is against the grain of modern education to teach children to
program. What fun is there in making plans, acquiring discipline in
organizing thoughts, devoting attention to detail, and learning to be
self-critical?
-- Alan Perlis
Why _not_ use them?
--Jeremy
--
I could say 'defensive programming'.
The named routes aren't explicit, as I understand it.
A malicious user could experiment with dynamically generating routes.
A fat fingered typist (I'm one, so I know!) could use typos as routes
that are incompatible with other parts of the code.
I favour pushing back the checks. Routing seems a good place to say
what is and isn't permitted.
--
Right now I'm having amnesia and deja vu at the same time. I think I've
forgotten this before.
No worries. I wasn't sure you could tell, and I want to help you
figure this out. I figured other people may have been having the
same reaction I was.
> Surely I can't be the only person so afflicted?
I hope not...you're all the market for my eBook that I haven't
written! :)
You are not alone. I have not been particularly impressed with REST as a
design paradigm for anything other than web services. While there are
certainly advantages to being able to create web services simply and
easily, I do not believe that good URL design for web services is the same
as good URL design for user-facing sites. Conflating RESTful web services
with good user interface doesn't make sense to me.
I might feel differently about it if the class of webapps I develop leaned
more toward Twitter or the like, but I typically create custom web
applications for nontechnical clients. There are requirements involving how
the site is laid out and how it feels to be a user, and no concern about
web services.
I'd like to hear some compelling arguments about why RESTful Rails
development matters even if web services are completely off the table, but
so far all I've heard is about how thinking of things as resources makes
for a nice design, which I'm not buying (see above).
--Greg
I could say 'defensive programming'.
The named routes aren't explicit, as I understand it.
A malicious user could experiment with dynamically generating routes.
A fat fingered typist (I'm one, so I know!) could use typos as routes
that are incompatible with other parts of the code.
I favour pushing back the checks. Routing seems a good place to say
what is and isn't permitted.
Best regards
Peter De Berdt
Good point.
As in "I wish I had said that".
Things like games and wikis ARE the user interface, in many ways.
> I might feel differently about it if the class of webapps I develop leaned
> more toward Twitter or the like, but I typically create custom web
> applications for nontechnical clients. There are requirements involving how
> the site is laid out and how it feels to be a user, and no concern about
> web services.
Yes, that applies to Wikis, and to the games I've seen and used.
> I'd like to hear some compelling arguments about why RESTful Rails
> development matters even if web services are completely off the table, but
> so far all I've heard is about how thinking of things as resources makes
> for a nice design, which I'm not buying (see above).
--
Expecting life to treat your fairly because you are a good person is
like expecting an angry bull not to charge because you are a vegetarian.
-- Shari R Barr
> Here's how REST makes sense though, and this is NOT made clear by Rails:
>
> Resources are NOT models.
>
> I built a simple system to control the lights in my house. I did it with
> REST. I ended up with two resources:
>
> a Unit, which is the resource to manage the creation, deleetion and
> modification of the X10 devices in my house.
>
> When the time came to actually turn on a light switch or turn it off, my
> first instinct was to add the following code to the Unit controller:
>
> def on
> @unit = Unit.find_by_id(params[:id]).on!
> end
>
>
> def off
> @unit = Unit.find_by_id(params[:id]).off!
> end
>
>
> But after thinking about it, what I'm doing is changing the STATE of the
> unit. Therefore, it made more sense to have a State resource.
...
> Notice how the state resource changed how I implemented the code to
> manipulate the light? Interesting stuff.
>
> This also made me realize that the show action (get) could tell me the
> current state of the light.
>
> Already I have less complicated controllers, though I have more.
>
>
> That's just my .02. :) I did a fun project to learn more about how REST can
> help me design things. I can share some code if anyone cares.
YEP! It's not so much the url structure as the view of controllers as
resource controllers that's important.
I got the same kind of epiphany from building one or two NEW
applications in rails 2.0 using rails view of restful design. It's
one of those paradigm shifts that you have a hard time getting until
you do.
And I think that the epiphany is more likely to come from trying a new
fairly simple app using REST than by struggling through converting an
existing one. After the epiphany you're much more likely to
understand what such a conversion really entails and how to do it
successfully.
--
Rick DeNatale
My blog on Ruby
http://talklikeaduck.denhaven2.com/
I'd like to hear some compelling arguments about why RESTful Rails
development matters even if web services are completely off the table, but
so far all I've heard is about how thinking of things as resources makes
for a nice design, which I'm not buying (see above).
Nothing is stopping me making system calls to custom C-code either, but
that's not the point.
I'm trying to ask HOW I can re-structure things to take advantage of
REST. I'm repeatedly told its 'good for you' but short on the HOW.
Lots of the hints don't make sense. A search method in the
WikiController could just as easily be a web service.
You go on to say
> You're completely missing the point of REST.
Yes, and its not the benefits I'm asking about, its the HOW.
Not the technical HTTP level how, but the code organization how.
And yes, I've read a lot about it and its stirred my interest, but its
still not telling me anything I can see how to USE. And by 'use' I mean
how to structure my code design to make sense and make use of it.
Because replacing what is now a method with a controller doesn't make
sense - not to me, and not unless there is some advantage that you guys
see that I don't and hasn't been stated. And thinning down the
WikiController isn't the advantage 'cos all the code is in
'lib/search.rb'.
Let me give an example of what I mean by the HOW.
A blog, sorry can't find it in my bookmarks quickly, suggested a skinny
controller full of 'def action end' and the code in the models views and
helpers. Well I managed to make one with all the code in the helpers.
Lots of DRY; the helper was really a 'library' for the 'calls' in the views.
The examples of RESTfulness I've seen, with the exception of 'restful
authentication' (and questions about that have gone unanswered) all seem
to focus on CRUD and the kind of routing I very much DO NOT want to use.
They really do not communicate any advantage. But so what; I've seen
code fragments that show Perl and PHP outperform Ruby - perhaps they do,
in fragments, but at the level of whole applications where the code is
in Ruby-idioms rather than merely translating Perl, then Ruby performs
at least as well as Perl.
I had to learn the Ruby idioms, and now I prefer Ruby to Perl. So I can
accept it when Jeremy says he can write RESTful apps fluently.
What I don't see is the HOW for anything but the basic CRUD.
Suppose I do that 'SearchController with one method' change, and work
though the changes to the routes (!?!). What do I do next? I can't
keep coming back here and asking 'what do I do next'. I need to
understand the HOW to convert (or redesign). That's what I'm seeking to
find out. And its why I'm frustrated by people simply telling me that
RESTfulness is a good thing.
--
Genius may have its limitations, but stupidity is not thus handicapped.
Elbert Hubbard
As I just tried to point out in a recent reply to this post, it's
probably better to learn how to first design using restful principles
for a simple new app before trying to re-design an existing app.
One small starting point might be to really understand the differences
between code generated by the the acts_as_authenticated and
restful_authentication plugins. Although that's probably too small an
'app' to demonstrate the benefits of going from a few complex
controllers to more but much simpler ones.
Clearly this is a book asking to be written. That it hasn't yet
appeared tells me that not many people (or at least not the right
ones) have a strong enough and solid grasp of it to write that book,
even if they personally know that it's a useful idea.
In the software development race I'm a tortoise. I plod along until
the next step has been clearly explained by one of the smart hares who
have figured it out. So while I feel a tinge of guilt that my app is
not RESTful and my controllers fat, it's not yet enough to get my
tortoise-behind to make the change.
And I don't worry that my current application will later seem
antiquated and in need of a massive rewrite - every program I've ever
written could benefit from a rewrite, and I expect that to always be
true for me, and usually true for almost everybody else as well.
You keep harping on "basic CRUD." As if "basic CRUD" applications cannot
be complex.
It might help you to watch this video of DHH explain his new-found love
for CRUD:
Also, I thought Brian Hogan did a pretty good job of explaining the
elusive "how."
Post: http://www.ruby-forum.com/topic/137572?reply_to=612281#612265
I'll reiterate what I find to be his most important part: Resources are
_not_ models.
Imagine a collection of clients. We can create, read, update and delete
those resources (forget that you may have an actual client model as
well).
But what about searching for clients? That doesn't seem to fit the CRUD
model. Except it does.
If we twist our brains, we might come up with a ClientSearches resource.
Notice I said resource. That means another controller. No new models
though. Just a different way of looking at our model.
With ClientSearches in our brains, it _does_ make sense to CRUD it. When
we perform a search we are _creating_ a new search.
That's REST.
I think someone else in this thread mentioned that a single resource
doesn't have to be restricted to one model. If I have an Account
resource, I could use the show method to display a Company object, all
their Client objects, and maybe even some Contact objects. Remember:
resources are not objects.
Also, REST is not limited to CRUD. You can easily define other actions
in your controllers provided the actions they carry out are respective
to their HTTP method. In Rails 2 (possibly lower versions, not sure) you
can specify a new custom route onto a map.resources command.
See this pod cast for more on that:
http://railscasts.com/episodes/35
Hope that helps answer the "how" portion of your question.
- Daniel
--
Posted via http://www.ruby-forum.com/.
Oops, here's the video:
http://www.scribemedia.org/2006/07/09/dhh/
I don't see the problem with searching at all and therefore may be blind
for what this solution offers, but I can't imagine why I would model(!)
searching as creating a resource.
What's wrong with
GET /clients?firstname=John&lastname=Doe
and handling it in ClientsController#index?
Michael
--
Michael Schuerig
mailto:mic...@schuerig.de
http://www.schuerig.de/michael/
Clearly this is a book asking to be written. That it hasn't yet
appeared tells me that not many people (or at least not the right
ones) have a strong enough and solid grasp of it to write that book,
even if they personally know that it's a useful idea.
Interesting. I never said there was a problem. And there's certainly
nothing "wrong" with your approach.
Some things are better learned through experience. For me, REST was
certainly one of them. Perhaps the same is true for you.
At this point I'd strongly suggest that if you _really_ want to
understand the how and why, you do it for yourself.
Obviously I hope you try the RESTful lifestyle and love it, but if you
don't, no hard feelings. =)
I'll look up the video when I get my codecs working, but ...
> I'll reiterate what I find to be his most important part: Resources are
> _not_ models.
OK, not a problem. See below.
> Imagine a collection of clients. We can create, read, update and delete
> those resources (forget that you may have an actual client model as
> well).
>
> But what about searching for clients? That doesn't seem to fit the CRUD
> model. Except it does.
For some values of 'fit'. See below.
> If we twist our brains, we might come up with a ClientSearches resource.
> Notice I said resource. That means another controller. No new models
> though. Just a different way of looking at our model.
>
> With ClientSearches in our brains, it _does_ make sense to CRUD it. When
> we perform a search we are _creating_ a new search.
No.
You're confusing an artefact of the language with the abstraction.
In Ruby you have to deal with classes and hence you have to do a 'new'.
If you look at the code base for TWiki you'll see they've made
everything an object. To do a save you hand the string to an object
that is the instance of the StorageManager rather than writing to a
file. There are lots of such objects. The startup code is full of
$this->{part} = new TWiki::Part( $this )
as the various parts (implemented as objects) are instanced and
references to them kept in one big 'context' object, and all further
operations indirect though that.
It makes the code ugly. Well uglier than Perl code needs to be. But
that's Perl and objects for you.
I point this out because a language in which each 'thing' is an object
can't be used (aka its methods) until you create an instance of that
object. Ruby is such a language. It doesn't matter if the Search class
is a controller or a library, you still end up doing
s = Search.new( ... )
You've made a 'virtue out of a necessity'. Of course we're creating a
new search. But that has nothing to do with a resource being a design
decision.
I've seen the likes of 'search' implemented many ways. With Ruby's
light-weight objects it makes sense to load stuff at create time.
In TWiki's Perl, there's just the one search engine for each context
(aka thread) so its completely parametrized when its invoked:
$this->{search} = new TWiki::Search( $this ) # 'new' per session
.....
$text = $this->{session}->search->searchWeb( .. huge argument list ...)
Now THAT is a design decision. That it is ugly and ungainly is an
artefact of the language!
So whether the design decision loads up at the time the search object is
instanced or when its method is invoked IS a design decision. You can
see a permutation on this with the use of the BruteMatch method used for
searching in the Socks-Wiki, another Ruby Project from before Rails.
The loading of the patterns and the search space are very spread out and
obscure, since, one again, the single engine is instanced into a context
object.
But unless you call the instantiation of the search object a
'create/INSERT//Post', and its going poof! when it goes out of context
and becomes a candidate for the garbage collector as a
'delete/DELETE/Destroy' there's not going to be a lot of methods. As
far as I can see a 'new()' and a 'do_the_search()'. No CRUD in it.
Or did I blink and miss something?
> That's REST.
See below.
> I think someone else in this thread mentioned that a single resource
> doesn't have to be restricted to one model.
Indeed. No argument, but that's a design an decision that is
independent of REST. My WikiController handles both the Web and the
Topic models in one gulp. If you look at Instiki, it does the same, and
updates other models that keep track of links and cross references.
While I'm mentioning it, would you call Instiki 'RESTful'?
If not, why not, and if so, why so.
> If I have an Account
> resource, I could use the show method to display a Company object, all
> their Client objects, and maybe even some Contact objects.
If I'm looking at a page in an address book the Person might have any
number of addresses and phone numbers. (Don't you hate the things like
ACT where there's only a fixed number of slots for phone numbers because
they are part of the Person record and not a separate 'has many' object.)
> Remember: resources are not objects.
Or at least they need not be. See 'restful authentication'.
> Also, REST is not limited to CRUD. You can easily define other actions
> in your controllers provided the actions they carry out are respective
> to their HTTP method. In Rails 2 (possibly lower versions, not sure) you
> can specify a new custom route onto a map.resources command.
>
> Hope that helps answer the "how" portion of your question.
No, if anything it leaves me more confused than before, for the simple
reason I'm doing most of that without anything looking what I've seen
described as RESTful.
My wiki has a controller that has no model behind it and my models don't
have corresponding controllers. The Wiki is the resource the user sees.
The webs and the topics in them aren't resources, they are content.
In fact I get puzzled why forums and blogs do nested routing.
If you look at the URL
http://reclusive-geek.blogspot.com/2006/11/peepcodes-restful-rails.html
there isn't a month controller in the year controller. The URL is
user-friendly, its not
/year/2007/month/11/post/peepcodes....
And since there's a lot of 'old code' that works this way its not a
feature of RESTfulness.
In fact the only controller in my wiki that that has a model behind it
or model with corresponding controller is the 'User' and that's
'restful authentication' and that has
new create activate
suspend unsuspend destroy
purge change_password forgot_password
reset_password find_user
And a deal of that was pasted in from 'acts_as_authenticated' and 'state
machine' as you can see. And I kept the named routes as well. So I'm
not bothered by 'beyond the CRUD'. Is this a 'fit the CRUD model'? I
wouldn't call it that. Not without squinting. I could remove the
'destroy' and 'purge' since there's no button on any of the views that
leads to them and its not part of the functionality. A user gets
suspended but the record is still there so that authorship can be
attributed. That's part of being a Wiki. I could delete those methods;
perhaps T should :-). And the login process don't offer a 'find' to the
user interface. You have to know the name or the activation code. So
its C-U-.
I have a (single) custom route for the wiki that doesn't involve any
'nesting' as there is only one relevant controller - the WikiController.
See above and previous postings. The 'restful controller', however,
uses lots of custom routes.
Sorry if this seems argumentative, but I'm trying to explain why I'm
saying "no it doesn't help explain the HOW'. Either I'm doing RESTful
design (and always have) without RESTful routing and without knowing it,
or there's something I'm not getting here.
--
The whole art of teaching is only the art of awakening the natural
curiosity of young minds for the purpose of satisfying it afterwards.
Anatole France (1844 - 1924), The Crime of Sylvestre Bonnard
But you appear to suggest that my approach is somehow not RESTful. I'd
take exception to that and claim that, yes, what I suggest is
completely in line with REST. And it is my understanding that the
authors of "RESTful Web Services" (Leonard Richardson & Sam Ruby)
agree. I highly recommend that book.
......
> Just my way of thinking, others will disagree I'm sure.
I agree with you 100%, Brian. The only time I've wanted to elevate
search to a separate controller is when it is doing multi-model
searches, and even then it was still a GET.
> link_to @topic.name, { :controller => "topics", :action => "view", :id
> => @> topic.id }
> when Restful Routing gives you:
> link_to @topic.name, topic_path(@topic)
I'm just starting rails, second week now, been into python and zope for
6 years. I actually find rails cool, but things like
topic_path(@topic)
takes me forever to FIND THIS convention. I need INSANE amounts of time
to find how everything is phrased, instead of just writing an extra line
of code.
Sorry for being off topic a bit here.
A
This is one commonly-touted benefit that isn't quite accurate. In
addition to knowing the URL, you need to know the structure and
semantics of the XML data. So while using it is obviously simpler
than if it were a WS-* service, it's certainly not free.
That's one of the promises of microformats. Of course, they haven't
quite taken off yet.
Pat
--Jeremy
--
http://www.jeremymcanally.com/
My books:
Ruby in Practice
http://www.manning.com/mcanally/
My free Ruby e-book
http://www.humblelittlerubybook.com/
My blogs:
http://www.mrneighborly.com/
http://www.rubyinpractice.com/
I found this, which seems to meet the 'non trivial' requirement.
It interested me because it was a refactoring and redesign, which is
what I've been trying to unearth in this thread. It seems to be a
'proof by example' rather than a 'proof by assertion'
http://scottraymond.net/2006/7/20/refactoring-to-rest/
It is just another 'talking point'?
http://www.sourcewatch.org/index.php?title=Talking_points
He gives numbers and lists of the 'before and after' and says "The
process was gradual.."
Maybe we can all ask him for more details.
--
The deepest sin against the human mind is to believe things without
evidence.
Thomas H. Huxley
I don't think that's a fair analogy, Brian.
I can read Latin, French, Spanish and a couple of other languages at
the 'find my way around the airport and order a meal' level. But I
can't write or peak them.
I wrote compilers early in my career, and interpreters and DSLs. I know
how computer languages work. I've earned a living writing in about 12
different ones including SmallTalk and FORTH, but I find RPN hurts my
social life (too much RPN during the day and it spills over into the
night). So _reading_ a language isn't a big deal. Figuring out other
people's code ...well that depends. I've done maintenance on some awful
code in my time, again for a living. It instilled me with "I don't want
anyone to think about me what I'm thinking about the guy who wrote that
code".
Rails is nice; the 'convention over configuration' means things are in
the right place when you come to look for them. It makes it much easier
to understand than some 'ad hoc' application. Compare Instiki with
Socks, both wikis written in Ruby, one in Rails, the other 'ad hoc'.
But you've tried to extend this to something else. I can read an
application written in RESTful Rails and understand it, but like reading
and understanding Latin or French, that doesn't mean I could compose one.
As for every application being CRUD, well I can see that if you're stuck
with Rails and the Web and a database backed system you're going to get
channelled that way. But people are using the Active* without database.
I can also imagine things like games where the CRUD might be used to,
for example, load the maps/terrains and flight characteristics for a
flight simulator, but the actual 'flying' isn't CRUD.
--
If you are using Windows 2000, there is no chance that DES is your
weak link. The only justification for using 3DES is that it is cheap.
-- William Hugh Murray, CISSP
I seem to have an uncanny knack of picking the maverick ones then!
When I think back, the only completely CRUD system I ever did was an
accounting package in DB 4GL called Progress.
I'm old enough and scared enough that I wok out alternatives before
implementing. I've been known to run many test examples to find out hwo
compilers 'work'.
Perhaps that's why I'm comfortable with 'constrained' approaches (you
call it 'convention over configuration' but its had other names in
history) rather than an 'infinitely rich colour pallet' for my artists
brush. If you'll pardon the analogy. I've found hat constraints means
focus.
So I get a lot of "yes, so what?" to that's being said about structuring
for REST. The slicing and dicing of command and control and
responsibility isn't new; I was taught it over 30 years ago.
> it's just that we haven't done it
> before and not sure how to tackle it.
LOL!
> Maybe this helps, think about
> the objects of you application, any object/noun can have its own
> controller-model-view, which in most cases will lead to more
> controllers but very simple controllers that you can understand in no
> time.
You grew up speaking English, I guess. Not all languages work that way
and some languages you have to match up the cases, declinations and
conjurations as well as temporallities. There there's languages like
Navaho which are so radically different you can't really comapre them
with the Indo-European ones.
English, the subject - verb - object, way is either terribly sloppy or
terribly tollerant depending on how you look at it. Native speakers can
gloss and use idioms that are unintelligble to ESL, and non native
speakers can produce terribly fractured English with cases and tenses
all wrong but still be understood. Few other languages are that
'tollerant'.
My point here is that even with the CMV, 'there's more than one way to
do things'. I can make my controllers skinny in number of ways; by
offloading code into the models, into the views, into the helpers or
into libraries. I can build a controller around no methods except
'method_missing'. I can build it with lots of exception handlers and
few "if" statements that do checking
(http://blog.codefront.net/2007/12/10/declarative-exception-handling-in-your-controllers-rails-20-a-feature-a-day-2/
http://railsforum.com/viewtopic.php?pid=49600
http://nullstyle.com/exceptional/
and others)
> So, instead of facing a 100 method controller you have 10
> controllers with 10 methods, and 7 of them are the same in all
> controllers. Isn't that beatiful and easy to understand?
You remind me of the English language teachers or possibly the "Business
Communication" who advocate short sentences with strong verbs and
concrete nouns. They are asking you to ruin the language. Here's a
pointer to a parody of one of the great works of our language with that
applied: http://norvig.com/Gettysburg/
John Kenneth Galbraith is one of the most clear, fluent writers of
technical and business English. In one of his books I encountered a
sentence that ran on for one and a half pages. I did a double take when
I realised it and went back and wrote the sentence out by hand,
decomposed it, and tried reformulating it a a number of shorter
sentences, with, alas, no success in preserving the clarity and impact
the original, and I do not believe that was due to any shortcoming in my
ability to handle the language. It was beautiful. It was graceful. It
was easy to understnad. But short it was not! (Now re-read this last
paragraph.)
One "traditional" way of judging code quality comes from the days of
"goto-ful" programming. With "GOTO" you needed to remember where you
came from as you flipped back and forth though the lsitings. So if you
needed more than a places where you had your finger stuck in the fanfold
as a placemaker it was called a 'more than five finger program'. On can
make the case that a single file is easier to scan that having ten
different controllers and having to grep to find which one has the
method, its all in one and your pinky finger just has to hit the '/'.
YMMV.
> Okay another advantage. Once you have 10 controllers instead of 1
> huge one, you can test it much better. Let me refrase that, spec
> it :) cause we like BDD, don't we? So, you can write simple specs to
> make sure each of those controllers does its job right, and that they
> all comunicate with each other correctly, using for example, the all
> might rspec Stories, which are freaking awesome :) So, your
> application will become easier to spec and thus to maintain and extend
> with confidence.
You're arguing in a circle.
> Another advantage. Information and continuous improvement of the
> site. In my opinion an app, is never complete, it can always be
> enhanced with new features, re-factored, made more robust and become
> more useful by deleting features that are of no important use.
And eventually become obsolecent ...
> Thus,
> if we all use REST we will be able to share information with other
> sites and enhance our own site with more information. This
> information needs to be readily available and easy to access and
> update.
That's a non sequitor. It may or may not be true; it may or may not be
an advantage, but it certainly doens't follow on from the previous sentence.
One can, for example, add a RSS feed, or an RSS input, to a site with
little difficulty, without needing REST. One might even think of RSS as
'just another "skin"' defined by different template.
> REST lays down the guidelines for everyone to have a common
> language. If I know you have a site about car rentals with all the
> rates in xml form at the url http://yousite.com/rates I don't need to
> know anything else to access your data and add it to my site.
I'm sorry: are you saying you need REST to output (or input) XML?
I don't think that's the case.
> As you can hopefully see, there is no one advantage about REST, its
> more of a synergy of small things that make the development of REST
> applications a happy and beautiful process, we like happy and
> beautiful right?
Actually no.
"The reasonable man adapts himself to the world; the unreasonable one
persists to adapt the world to himself. Therefore all progress
depends on the unreasonable man."
--George Bernard Shaw
Discontent presents a challenge.
> Hope that helps
____ ___ ____ _ _
__/\__/ ___|_ _/ ___| | | |_/\__
\ /\___ \| | | _| |_| \ /
/_ _\ ___) | | |_| | _ /_ _\
\/ |____/___\____|_| |_| \/
--
There are only 10 kinds of people in the world:
Those who understand binary, and those who don't.
I am curious to hear from people more in detail about something:
If you consider RESTful Rails approach to be useful, have you always
been convinced? If so, why did you jump on the wagon so quickly? If not,
what was the primary thing that contributed to you eventually being
convinced of the merits of REST.
If you consider the RESTful Rails approach to be not so useful and do
not plan on using it yourself in the future... have you ever tried the
RESTful approach? If not, what stops you from at least giving it a
chance for one application before making judgement? If you have tried it
and never intend to use it much again, what were the reasons that you
found it to be lacking. Any suggestions on how to improve it in the
future?
As for my personal take, I have been doing non-REST Rails for a long
time and I was frankly skeptical that it would be worth my time to
learn. I wasn't planning on using it, I had watched the tutorials, read
the posts and it just wasn't convincing. Then, I started work on a
project with a team member who was sold on REST and we developed in a
RESTful way for Rails 2.0 and now I am a believer as well. I won't go on
rambling much longer but I concur with a lot of what the RESTers are
saying and I really enjoy sticking with the "convention" which in Rails
2 is fairly obvious.
Wow. You guys definitely take these discussions pretty seriously. Each
person counter-arguing back and forth on every point the previous person
made. That is impressive how much the community cares about getting to
the bottom of "Why REST". Interesting to see so many opinions on both
sides as well as the truthful "I just don't understand yet..." posts.
I am curious to hear from people more in detail about something:
If you consider RESTful Rails approach to be useful, have you always
been convinced? If so, why did you jump on the wagon so quickly? If not,
what was the primary thing that contributed to you eventually being
convinced of the merits of REST.
I can also imagine things like games where the CRUD might be used to,
for example, load the maps/terrains and flight characteristics for a
flight simulator, but the actual 'flying' isn't CRUD.
THANK YOU ! ! ! !
At last, something tangible instead of the same old hoary oft-quoted
examples.
THANK YOU ! ! ! !
(Only 4 exclamation marks. I take not of what pTerry said.)
Now I just need a brainstorm to see how that maps to what I'm doing.
What I'm faced with is that apart from the web services of 'list'
there's not a lot of public-facing functions for the parts of a wiki.
Even the models themselves aren't actually public facing since the sole
'resource' is the wiki itself.
Another way of looking at this: an admin interface might let you get at
the individual tables and bypass referential integrity - or patch it up
for maintenance purposes. But you don't want a publicly exposed URL
that can be hacked. (If you want I'll start a branching thread about
security trivia.)
In this example, the GUI may have buttons for the planes controls, but
there are other 'resources', internals like fuel and internal state
("Houston, we have a main bus A undervolt now, too... It's reading 25
and a half. Main bus B is reading zip right now... We got a wicked
shimmy up here.") Well not quite. But fuel consumption and how it
affects COG are flight characteristics are internal functions not
something that's exposed as a URL.
This is is one of the conceptual issues I'm facing.
Or let me put it another way. There is a flying technique where you
don't touch the throttle. The user interface is the joystick.
joystick.forward is an exposed function. The ensuing plane.tilt causes
a time dependent plane.increase_speed and plane.decrease_altitude and
plane.have_wings_ripped_off_at_roots and plane.crash_onto_ground, but
those are not exposed by any URL. Or at least in a good design they
are not, since the interface is only there to model the available controls.
Note also that some of those functions are timed and not a response to
the user clicking a button.
Now my analogy only goes so far because while plane engines (or at least
the 'small' prop-driven ones I'm familiar with) do have engines which
run at 'constant revs' (unlike auto engines), they also have throttles
(how else would you start them up?).
But I'm sure we can come up with a 'resource' that not only must not
have any functionality exposed, but one whose operational integrity can
be subverted by using a URL with suitable parameters.
Lets face it, that
map.connect ':controller/:action/:id'
or its equivalent is a security risk.
(If you don't see why then good for you; you're one of the 'good but
naive' guys.)
--
The only freedom which deserves the name, is that of pursuing our own
good in our own way, so long as we do not attempt to deprive others of
theirs, or impede their efforts to obtain it.
--John Stuart Mill (On Liberty, 1859)
Now I just need a brainstorm to see how that maps to what I'm doing.
What I'm faced with is that apart from the web services of 'list'
there's not a lot of public-facing functions for the parts of a wiki.
Even the models themselves aren't actually public facing since the sole
'resource' is the wiki itself.
> CRUD to me is something specific.
For me too.
> But just what are 'restful resources'.
Good question. I find the concept of a 'resource' a bit fuzzy.
> I would really like to see the concepts grounded in a
> more concrete way.
Me too.
> Isnt a restful resource actually a CRUD resource??
Some peole here are saying everything reduces to CRUD.
> I can already hear you say - well no it isnt quite!
Who? Me?
> Then
> exactly what is it? In my understanding, I could make a restful web
> service and not use the CRUD operations.
Not difficult.
> But that would clearly not
> be what Rails is meaning by restful resource. In some way it is
> relating to the verb/noun url paradigm.
Ah. Look at my above responses. I've made them deliberately short, but
they do illustrate that you don't need 'verb/noun' sentences to be
intelligable. Its not that difficult to construct longer sentences
without either verbs or without nouns. Without both takes a bit more
effort.
> But what has that got to do with REST.
Indeed.
> I hope you can see my confusion here.
Yes.
> I reckon that there
> are several concepts lurking under the term rest which are implicitly
> understood, but not explicitly tangible to those like me who have not
> yet managed to fully enter in with their thought processes.
Me too.
>
> In summary then - I think I like it, I want to use it, but I can't
> quite grasp it.
Me too.
> Tonypm
>
--
In view of the stupidity of the majority of the people, a widely held
opinion is more likely to be foolish than sensible.
--Bertrand Russell, Marriage and Morals
And this is key. Until you really get what a Resource is, REST in
Rails is just a naming convention.
A Resource is any thing in your application that has at least one
name (URL) that uniquely identifies it.
The fundamental change in RESTful thinking is to think in terms of
these things with names, and about the things they can do for us when
we ask them to.
> Some peole here are saying everything reduces to CRUD.
When DHH brought REST to Rails, he got hooked on the REST == CRUD
metaphor. Sometimes (often) that works, but sometimes it doesn't.
So it's more than just CRUD, but that's a good place to start.
??
Isn't that what we've bee doing for the last 40 years that I've been
programming? It was certainly the way I was taught. Do they teach
differently these days?
>> Some peole here are saying everything reduces to CRUD.
>
> When DHH brought REST to Rails, he got hooked on the REST == CRUD
> metaphor. Sometimes (often) that works, but sometimes it doesn't.
Thank you. I suspect admitting that takes some courage :-)
--
For ages, a deadly conflict has been waged between a few brave men and
women of thought and genius upon the one side, and the great ignorant
religious mass on the other. This is the war between Science and Faith.
The few have appealed to reason, to honor, to law, to freedom, to the
known, and to happiness here in this world. The many have appealed to
prejudice, to fear, to miracle, to slavery, to the unknown, and to
misery hereafter. The few have said "Think" The many have said "Believe!"
--Robert Ingersoll (Gods)
Not at all.
REST predates Rails, and REST is more than CRUD. The Rails
implementation of super-easy REST is very CRUD oriented, and it's a
decent metaphor. It's not an absolute, though.
I didn't say REST didn't apply everywhere. I maintain that by
definition, every web application can be modeled in terms of resources.
Just that it's not necessarily CRUD.
I was rewatching the Railsconf 2006 keynote from David and its all about
REST.
He talks about the implementation of REST in combination with has_many
:through.
I think its a very good talk if you want to know more about REST.
Even without the slides you can follow a long quite well.
It gives a clear insight on how he was thinking at the time.
Its up for grabs here.
http://blog.scribestudio.com/pages/rails/
You want the David Heinemeier Hansson download.
And do yourself a favor and watch Martin Fowler.
Now don't go hammer the server all at once :-)
Regards.
Peter Dierx
http://www.railstation.eu/blog
PS
I will post this in 'REST Style' and 'WHY Rest'
--
Ryan Bigg
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.