Good work! Everything is solid except for what is mentioned below. So if it's not below, you are good. Here are my notes on your code:
##Views##
- When I go to the edit form at
http://localhost:9393/entries/:id/editthebodyof the existingentrydoes not show in the correspondinginputfield. It looks like this is because you are utilizing atextareatag in your entries/edit view. Heads up: It doesn't look like thetextareatag supports thevalueattribute, according to the docs. That would explain why thebodydoesn't show on theeditform. You will need to fix this, since the user will think theentrydoesn't have abodyat all (which is not true). - Watch out: Your
entries/newview cannot handle a request from a user who is not logged in (because the view assumes thatcurrent_useris notnil). How can you adjust this view so that it can handle a request from a user who is not logged in (e.g. the user manually typeshttp://localhost:9393/entries/newinto their browser's address bar)?
#Authorization##
- Watch out: Currently any user can edit or delete any entry, even entries the user did not create. (While you have successfully hidden the edit and delete links from the view of unauthorized users, you have not protected the
putanddeleteroute actions themselves, which means if I typehttp://localhost:9393/entries/1/editinto my browser's address bar, I can edit entry 1 even if I have not created it. Also if I use a simple http program like curl I could also delete entry 1 by sending a delete request.) How can you add controls to your edit and delete route actions, so that only the creator of an entry can edit or delete them?
##dependent: :destroy##
- Your uses of
dependent: :destroyare syntactically correct. But watch out: while it makes sense to automatically delete all of theentry_tagsassociated with anentry(since they would become orphaned records when their correspondingentryis deleted), it does not make sense to also automatically delete all of thetagsassociated with anentry, since otherentryrecords may also be associated with thosetagrecords. Challenge: can you figure out a way to delete the correspondingtagrecords only if they would be orphaned as a result of thedestroycall on theentryobject? Hint: it can be done.
##Users##
- Watch out: You can currently create new users with no passwords. Not good.
##Instance Variables##
- In this route action you utilize an instance variable
@userbut you don't use it outside of this action. (Theredirectcan't receive any state, and theusers/loginview doesn't utilize@user.) Thus you should use a local variable (user) instead of an instance variable (@user). Only use instance variables to utilize them outside of the current method.
##Error Handling##
- If an edit of an entry is not successful, no error message shows because your put route action has no error handling. (But your
entries/showview does have error handling! So all you need to do is pass@errorsto theentries/showview.) - If the user tries to create a new profile, but does not enter any text in the username field, the error message that appears is
username already existswhich doesn't make any sense. Can you figure out how to assign a specific error message to thepresence: truepart of the validation, and another error message to theuniqueness: truepart of the validation? Hint: it's already done for you. Another hint: read the entire section 1.4 in the previous link, especially the longer code example.
##Logout and Delete##
- To answer your question: Your logout and delete forms are cool as-is. They work and are RESTful.
- FYI you could also do logout and delete as links, although any HTML link would be sending a
getrequest to your controller. The only way (that I know of) to have a link send a truedeleterequest is to utilize event handlers and ajax. Note: I do not think you need to do this; your forms work and are sufficient (unless your instructors tell you otherwise; do what your instructors tell you to do).
##Missed Something?##
- It doesn't look like users have the ability to edit tags on existing posts. (I'm not sure if this is part of the requirements of the challenge.)
Good work! 👍 Any questions let me know.
-Phil