- all?
- any?
- count
- each_slice
- each_with_index
- each_with_object
- find
- find_all
- find_index
Migration table naming convention:
groups_users
Migration file naming convention (the part of the file name that is not automatically generated):
create_groups_users
Model class naming convention:
GroupsUser
Here are the docs and here is a highly rated StackOverflow answer. (The docs are pretty long, you will probably want to search the web page for "unique" to find the relevant info.)
Bottom line: You need to create an index and make the index unique:
add_index :table_name, :column_name, :unique => trueHope this helps. Any questions let me know.
Good stuff, here are my notes on your code:
-
You are getting this, good work! 👍
-
This test does the job. Be aware though: Rspec comes with built-in expect change test capabilities, which can test if an object changes. (For example, if the length of an array increased by 1.) This will come in handy in the very near future.
-
Note: You caught this error while I was writing this! Nice work! Here is what I wrote anyway:
This is a really tricky one to catch and is a good teaching moment: take a look at this test, which currently passes when it
This is good stuff, here are my notes on your code:
- Good job protecting against spoof posts by manually assigning the
author_idtocurrent_user.idand also restricting author_id from yourpost_paramsmethod. 👍 👍 👍 - Good work having
if logged_in?logic on all of the appropriate views! 👍 - When searching by id number, instead of using
find_byit is best to usefindsince that method is designed to search on the id field. [Here are the docs onfind](http://guides.rubyonrails.org/active_record_querying.html#retrieving-a-single-ob
Good work, here are my notes on your code:
- Watch out: your post controller is allowing
user_idto be passed as a param. This means a client could easily spoof themselves as another user and create posts as someone else (by passing someone else's user_id in the params, perhaps via a command-line http tool like curl). You are going to want to removeuser_idfrom yourpost_paramsmethod and instead hard code the adding ofuser_idto the post viasession.user_id. You always want to get your user id from thesession.user_id, sincesessioncannot be spoofed. - Instead on using
find_bywhen searching by a unique id number (like you do [here](https://github.com/nyc-chorus-frogs-2016/build-a-rails-blog/blob/pair-edwardgemson%2Ckerryimai/blog/app/controllers/pos
Good work! Your code does the job. Here are my notes on your code:
-
You are utilizing jQuery's
onmethod for aclickevent on your form'ssubmitbutton, which works. But there is a better way. Because we are dealing with a form's submit action, you could utilize jQuery'sonmethod for asubmitevent, which would look like this:$('#style_editor').on('submit', function(event) { //#style-editor is the id of the form
Notice the
submitevent only requires you to locate the form (it automatically knows you are referring to the form's submit action). When binding event handlers to form submit actions, you are going to want to utilize this.
Note: You could also utilize jQuery's submit method directly.
Good work! Per your desire to sharpen your MVC skills, here are some detailed notes on your code:
-
You have a
putscall in yourDisplayclass'sinitializemethod. Instead, you are going to want yourControllerto utilize yourDisplay.look_at_thismethod to print this initial welcome text to the console:@viewer.look_at_this("Welcome to the World's Simplest Browser")
Or, you could write a specific Display method for this:
This does the job. Good work. Here are my notes on your code:
-
It looks like you unnecessarily separated the parsing work into two methods, your
get_listmethod and yourparse_people_objects_from_filemethod. All of this logic could be contained withinparse_people_objects_from_file; there is no need to separate some of the logic into aget_listmethod. This is how you could combine both methods:def parse_people_objects_from_file csv_row_objects = [] CSV.foreach('people.csv', headers: true) do |line| csv_row_objects.push(line) end
Good work! Here are my notes on your code:
- Good overall use of
fetch. Take a look at this for some subtle differences when usingfetchthat you will need to be aware of. (It looks like you are already aware, but just to make sure.) Notice specifically hownilandfalsevalues are handled differently byfetchand[] ||. - Interesting choice to pass default values to only four specific attributes. I am guessing you did this just to see what it would do? If so, good job on exploring.
- Good job using
fetchfor setting boolean values. If instead you utilized `[] |