vendredi 7 avril 2017

Rails how to hide form after save?

this is the case:

models/product.rb

belongs_to :brand

models/brand.rb

has_many :products

controllers/products_controller.rb

class ProductsController < ApplicationController 
  def new
    @product = Product.new
    @brands = Brand.all
  end

  def create
    @product = Product.new(params[:product])
    if @product.save  
      redirect_to :show
    else
      render :new, format: :html
    end
  end    
end

On product create the user can add a brand name and if the user add a brand name on next time to create a product the form for the brand did not show again.

Someone please have a idea how to do something like that on rails?

Aucun commentaire:

Enregistrer un commentaire