Skip to content

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

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

ASPhillips8
Copy link
Contributor

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.
Screenshot 2024-08-19 at 2 00 39 PM
Screenshot 2024-08-19 at 2 00 33 PM
Screenshot 2024-08-19 at 1 15 31 PM

@ASPhillips8 ASPhillips8 marked this pull request as draft August 20, 2024 12:37
Copy link
Contributor

@stephenmckeon stephenmckeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work :D

Comment on lines +8 to +9
rescue ActiveRecord::RecordNotFound
redirect_to vendors_path, alert: "Sweet not found"
Copy link
Contributor

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)
Copy link
Contributor

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'
Copy link
Contributor

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:

Suggested change
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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<li> <%= link_to vendor.name, vendor_path(vendor) %></li>
<li><%= link_to vendor.name, vendor_path(vendor) %></li>

Comment on lines +11 to +13
<% @vendor.vendor_sweets.each do |vs| %>
<li> <%= vs.comment %></li>
<% end %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't be lazy!

Suggested change
<% @vendor.vendor_sweets.each do |vs| %>
<li> <%= vs.comment %></li>
<% end %>
<% @vendor.vendor_sweets.each do |vendor_sweet| %>
<li> <%= vendor_sweet.comment %></li>
<% end %>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants