W4D5 - RedditClone
Topics
Rails App
Authentication
MVC - Model-View-Controller
Checked Boxes in HTML
Polymorphic Associations
Projects
RedditClone
Partner: Kat Telles
Learnings
before_action :require_login - jump to login page if not logged in
Commas in link_to "link text" destination_url - commas are required, will get expected keyword end error
Can pass a query_string "?sub_id:2" into URL so destination of button can parse params[:sub_id]
<%= link_to "Create new post", new_post_url(sub_id: "#{@sub.id}") %>
Error "You need to supply at least one validation" -- means you most likely forgot to write presence: true as an option in validates :thing1, :thing2
Place in stylesheets/application.css to apply default textarea size (or other defaults) on all web pages
input[type=textarea]{ width: 500 px; height: 150 px; }
Use save rather than save! in if/else blocks, since save returns false when it fails, whereas save! throws an error
Polymorphic associations - validate object rather than id
class PostSub validates :post, :sub, presence: true end
inverse_of - must put on both has_many and belongs_to sides of the association. Allows you to reference an association before the object is saved to the DB










