I remember once seeing the ability to define at the top of a controller the parameters that an action requires to work. For the life of me I can’t seem to find any mention of that capability anymore and it would be useful for the following:
def sort
params[:links].each_with_index do |id, index|
@link_set.links.in_context(context).update_all(['position=?', index+1], ['id=?', id])
end
render :nothing => true
end
I’m expecting params[:links] so if some smarty decides to visit that action without giving me params then it fails with nil.each_with_index.
It’d be nice to gracefully give a 404 or something if the parameters are missing without having to code this into every method of this type.
Does this exist? 🙂
Actually, stumbled across this article: http://rails.nuvvo.com/lesson/6376-action-controller-verification
The method is called verify and you can specify things like parameters to expect. 🙂