«« Next » « Previous
«« Next » « Previous

Link Details

If you don't vote, who will? Login and vote now.
Link 9814 thumbnail
User 194680 avatar

By bonlebon
via www-128.ibm.com
Published: Dec 26 2006 / 17:57

Ruby on Rails provides an excellent platform for building Web applications. Discover how to use the built-in Asynchronous JavaScript™ + XML (Ajax) features of the platform to give your application the Web 2.0 rich user interface experience.
  • 10
  • 0
  • 1335
  • 264

Comments

Add your comment
User 207929 avatar

fallenrogue replied ago:

2 votes Vote down Vote up Reply

I don't really want to throw down a complaint on this article as the purpose is well intended. I would say, however, that some of the syntax in the examples is either deprecated or simply not good practice. There are at least 4 examples of poor Ruby practice in the examples that I would stress should be avoided I'll list one to support my point...

class RecipesController < ApplicationController
def add
@recipe = Recipe.new
if request.post?
@recipe.name = params[:recipe][:name]
@recipe.description = params[:recipe][:description]
@recipe.ingredients = params[:recipe][:ingredients]
@recipe.instructions = params[:recipe][:instructions]
@recipe.save
end
end
end

Really? I don't think so. It should be...

class RecipesController < ApplicationController
def add
if request.post?
@recipe = Recipe.new(params[:recipe])
if @recipe.save?
#do something
else
# do something else
end
end
end
end

This seems small but Rails is trying to keep things simple and DRY. By using the suggested syntax (by the author, not me.) then you must go back and refactor your controller if you add or remove properties from this object. Once again, I credit the author for meaning well with this article but I found it to be well intended but not well coded.

User 205047 avatar

Lowell Heddings replied ago:

1 votes Vote down Vote up Reply

Agreed.

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Voters For This Link (10)



Voters Against This Link (0)