public

Is this unless block really needed? n.attribute?

  • Download Gist
ThugNotes PUT block Edit
1 2 3 4 5 6 7 8 9 10 11 12 13
# 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
ThugNotes PUT block original
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.