Rails - Non-Scaffolded Read and Create - sample of training off of youtube#

The original video is here youtube: Rails - Non-Scaffolded Read and Create

create the app#

Misc things#

seeds.rb#

Product.destroy_all

1000.times do
  Product.create(
      title: Faker::Commerce.unique.product_name,
      description: "Surprisingly this product is made out of #{Faker::Commerce.material}.",
      price: Faker::Commerce.price,
      stock_quantity: Faker::Number.number(3))
end

puts "Created #{Product.count} products."

Some trick re Rails forms#

<%= form_for @product, remote: false do |f| %>
> the remote: false -> during debugging of code (something relating to Ajax form submission)

# then next line - check on errors
<% if @product.errors.any? %>   # this is auto-set by model

WHITELIST form fields#

def create
  article = Article.new(article_params)
end

private
  def article_params
    params.permit(:title, :body)
  end