Guys:
I spent about a year fighting RESTful design in Rails for the reasons you've
outlined. I don't like things that are "cool" most of the time. I like
things that work.
However, the more things I've done with RESTful design, the more I truly
appreciate it. The thing is that people can explain it to you until they're
blue in the face but you're never going to "get" it unless you have
experienced it successfully.
For me, it was forcing myself to think about making everything work within
the default seven actions (index, show, create, new, edit, update,
destroy). You'd be surprised how often that works.
Need to view something? GET to show and pass the id.
Need to view all things? GET to index
Need to create something? POST to index
Need to change something? PUT to update and pass the id
Need to remove something? DELETE to destroy and pass the ide
Really, there's nothing different here than what you've done all along.
<%=form_tag {:controller => "posts", :action=>"create"}, :method => "post"
%>
still works just fine.
However, the REST convention makes it a lot easier.
<% form_for @post do |f| %>
If @post is a new record (no id, or id is nil, then the helper knows it
needs to POST to the create action. Just like how activerecord doesn't need
to be told what the primary key is, or what the table name is.
If @post has an id, then it knows the form needs to be a PUT request to the
UPDATE action.
Similarly, while I can do this:
<%=link_to "Create a new post", :controller=>"posts", :action=>"new" %>
I can just do
<%=link_to "Create a new post", new_post_url %>
In controllers and tests, it works together too!
if @post.save
# go to the list page
redirect_to posts_path
else
....
def test_should_redirect_to_list_when_created_successfully
Post.any_instance.stubs(:save).returns(true)
post :create
assert_redirected_to posts_path
end
So, what I'm saying is that once you learn how it all falls together, you
actually have less to think about.
"Where does the "change password" stuff go? new action called
"change_password"? No! It's an update! Maybe an additional view to show
the form for requesting the change, but the change itself is an update.
"Where do I do a search for posts? a "results" action? No! The index action
alreadt returns all the posts paginated by 20 at a time, just pass your
querystring there and use the controller to narrow the results down.
I'm more than willing to help any of you wrap your heads around this because
it's been a long journey for me to get here and I wish I had someone to help
me get where I am. I'd love to save you the trouble.
I don't, however, think that the "old style" ways are going away.
On Fri, Nov 14, 2008 at 9:58 AM, Robert Walker <
[EMAIL PROTECTED]> wrote:
>
> Rodrigo Rosenfeld Rosas wrote:
> > Rob Nichols wrote:
> >
> >>
> >> Is Rails moving to a pure RESTful design? I don't like REST but love
> >> Rails. I'd hate to think that as Rails develops it will become more
> >> difficult to use it RESTlessly.
> This is just my 2 cents: You have chosen an opinionated framework, you
> likely knew that when you started using Rails. The point to REST in
> Rails has little to do with web services, it's about applying convention
> to the structure of controllers and request routing. REST makes adding a
> web service API on top of your application easy, but the point is still
> the convention and not specifically to make web services.
>
> As for me I'm a big proponent of the RESTful design. In other words I
> happen to agree with the opinion of Rails. That does not mean that you
> should agree with the opinion yourself.
>
> So will Rails continue down the path to RESTful patterns? I'd say the
> answer to that is very clear. Can you still design your applications
> today without using the RESTful convention? Sure you can. Will it be
> more painful? Probably.
>
> I would say in your situation: maybe it's time to evaluate whether Rails
> is "in-line" with your opinion because your individual opinion is not
> likely to affect the opinions of the core team (who have obviously
> embraced a RESTful design).
>
> "If you've boarded a ship headed toward a destination that you don't
> want to go, then maybe it's time to start looking for a port where you
> can board another ship."
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---