If you don't vote, who will? Login and vote now.
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.
Comments
fallenrogue replied ago:
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.
Lowell Heddings replied ago:
Agreed.
Voters For This Link (10)
Voters Against This Link (0)