- 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 => true
Hope 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_id
tocurrent_user.id
and also restricting author_id from yourpost_params
method. 👍 👍 👍 - Good work having
if logged_in?
logic on all of the appropriate views! 👍 - When searching by id number, instead of using
find_by
it is best to usefind
since 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_id
to 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_id
from yourpost_params
method and instead hard code the adding ofuser_id
to the post viasession.user_id
. You always want to get your user id from thesession.user_id
, sincesession
cannot be spoofed. - Instead on using
find_by
when 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
on
method for aclick
event on your form'ssubmit
button, which works. But there is a better way. Because we are dealing with a form's submit action, you could utilize jQuery'son
method for asubmit
event, which would look like this:$('#style_editor').on('submit', function(event) { //#style-editor is the id of the form
Notice the
submit
event 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
puts
call in yourDisplay
class'sinitialize
method. Instead, you are going to want yourController
to utilize yourDisplay.look_at_this
method 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_list
method and yourparse_people_objects_from_file
method. All of this logic could be contained withinparse_people_objects_from_file
; there is no need to separate some of the logic into aget_list
method. 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 usingfetch
that you will need to be aware of. (It looks like you are already aware, but just to make sure.) Notice specifically hownil
andfalse
values are handled differently byfetch
and[] ||
. - 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
fetch
for setting boolean values. If instead you utilized `[] |