-
Notifications
You must be signed in to change notification settings - Fork 6
Create Show Pages With Form #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Create Show Pages With Form #3
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work :D
rescue ActiveRecord::RecordNotFound | ||
redirect_to vendors_path, alert: "Sweet not found" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine, but not something we really NEED to do.
class VendorSweetsController < ApplicationController | ||
def create | ||
@vendor = Vendor.find(vendor_sweet_params[:vendor_id]) | ||
@vendor_sweet = @vendor.vendor_sweets.build(vendor_sweet_params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although this works, you don't need to use build
here since vendor_id
is already included in the params.
if @vendor_sweet.save | ||
redirect_to vendor_path(@vendor) | ||
else | ||
render 'vendors/show' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be consistent with the quotes you're using. Try to always use double quotes:
render 'vendors/show' | |
render "vendors/show" |
<h2>Vendors Selling This Sweet</h2><br> | ||
<ul> | ||
<% @sweet.vendors.each do |vendor| %> | ||
<li> <%= link_to vendor.name, vendor_path(vendor) %></li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<li> <%= link_to vendor.name, vendor_path(vendor) %></li> | |
<li><%= link_to vendor.name, vendor_path(vendor) %></li> |
<% @vendor.vendor_sweets.each do |vs| %> | ||
<li> <%= vs.comment %></li> | ||
<% end %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't be lazy!
<% @vendor.vendor_sweets.each do |vs| %> | |
<li> <%= vs.comment %></li> | |
<% end %> | |
<% @vendor.vendor_sweets.each do |vendor_sweet| %> | |
<li> <%= vendor_sweet.comment %></li> | |
<% end %> |
Created a index and show page for two models (Vendor and Sweets). Pages had links that redirected to show pages per instructions. Vendor show pages has a form to create new associations with a sweet. The sweet will display on page and form requires a comment.


