Skip to content

Instantly share code, notes, and snippets.

@malachaifrazier
Created June 29, 2012 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malachaifrazier/3019890 to your computer and use it in GitHub Desktop.
Save malachaifrazier/3019890 to your computer and use it in GitHub Desktop.
Is this unless block really needed? n.attribute?
# Are the 'n.attribute' and 'unless' blocks really needed here?
put '/:id' do
n = Note.get params[:id]
n.content = params[:content]
n.complete = params[:complete] ? 1 : 0
n.updated_at = Time.now
if n.save
redirect '/', :notice => "Note updated thuggishly."
else
redirect '/', :error => 'Update failed, son.'
end
end
put '/:id' do
n = Note.get params[:id]
unless n
redirect '/', :error => "No Note to be found, son."
end
n.attributes = {
:content => params[:content],
:complete => params[:complete] ? 1 : 0,
:updated_at => Time.now #.strftime("%m/%d/%Y %I:%M%p")
}
if n.save
redirect '/', :notice => "Note updated thuggishly."
else
redirect '/', :error => 'Update failed, son.'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment