Re: What's the real advantage of REST ?

Back on topic. I've been wondering lately how rest degrades with js turned off? Does it completely break? Since restful authentication uses delete for logout can users not logout without js?

@raif: I wish we had PMs cause I have some question about how to actually insert things into facebook and the FBML.

http://www.brianthecoder.com

Rails, Javascript, Actionscript and More.

Re: What's the real advantage of REST ?

You could use a form button (button_to) to have it work with javascript turned off.

Alternatively you can create a custom route which doesn't require the "post/put/delete" method. However this may be triggered (unintentionally) through a bot or something. So whether you're using REST or not, it's best to place destructive actions behind post/put/delete requests.

Railscasts - Free Ruby on Rails Screencasts

Re: What's the real advantage of REST ?

ryanb wrote:

As mentioned above, I don't use nested routes. If that's what you're getting hung up on, don't use them for now. You can do everything without them - it's just the URL isn't as pretty. For example:

/users/1/posts
# vs.
/posts?user_id=1

They both have the same effect. If you don't use nested routes you aren't forced to pass the user_id in times you don't want to:

/users/1/posts/5
# vs.
/posts/5

I recommend not using nested routes at the beginning. If you want cleaner URLs you can add them back, but you will have tackled most of REST by then. Nested routes have a tendency to distract you from the important parts of REST IMO.

Ahh how silly of me, I could simply add a params check on the index action that queries the database.. doh smile

What would be the cleanest code in your opinion to do this? You always have the best smile

http://danielfischer.com - Personal Web-Technology-Blog, Los Angeles.

Re: What's the real advantage of REST ?

Is this what you are looking for?

def index
  if params[:user_id]
    @user = User.find(params[:user_id])
    @posts = @user.posts
  else
    @posts = Post.find(:all)
  end
end

Can't think of a cleaner way to do this at the moment. This assumes you need the @user instance variable - if not you could just put the user_id in the post find condition.

Railscasts - Free Ruby on Rails Screencasts

Re: What's the real advantage of REST ?

you could do
@posts = (params[:user_id])?User.find(params[:user_id]).posts:Post.find(:all)
though its a little harder to read.

http://www.brianthecoder.com

Rails, Javascript, Actionscript and More.