W7D3 Flashcards
By default what do we get back from the database when we make a request for data in our Rails controllers?
By default, we get all attributes, which is bad because we will send everything to the client, including password digests.
What does Jbuilder do?
Jbuilder constructs JSON views with curated data using Ruby.
In place of Rails views(.html.erb), what will we use?
We will Jbuilder templates with the extension of ‘.json.jbuilder’.
What does Jbuilder template do?
Jbuilder templates are there to be compiled by the Rails and you’ll be left with a JSON template.
What do you want to do in the routes if you use JSON templates?
You want to set the default format of resources to :json, which will allow Rails to automatically look for .json file.
What are the basic concepts of normalizing data?
Normalized state allows:
- Each type of data gets its own ‘table’ in the state.
- Each ‘data table’ should store the individual items in an object with the IDs of the items as keys and the items themselves as the values.
- Any references to individual items should be done by storing the item’s ID.
- Arrays of IDs should be used to indicate ordering.
What is the purpose of normalized state?
Normalized state is used to manage relational data or nested data in the Redux store by treating a portion of your store as a database.
What’s going on in the code below?
const blogPosts = [ { id : "post1", author : {username : "user1", name : "User 1"}, body : "......", comments : [ { id : "comment1", author : {username : "user2", name : "User 2"}, comment : ".....", }, { id : "comment2", author : {username : "user3", name : "User 3"}, comment : ".....", } ] }, { id : "post2", author : {username : "user2", name : "User 2"}, body : "......", comments : [ { id : "comment3", author : {username : "user3", name : "User 3"}, comment : ".....", }, { id : "comment4", author : {username : "user1", name : "User 1"}, comment : ".....", }, { id : "comment5", author : {username : "user3", name : "User 3"}, comment : ".....", } ] } // and repeat many times ]
blogPosts is trying to access the entire database of posts, which will cause nesting. It is not using normalize state to treat a portion of the store as if it were a database