user3905353
user3905353

Reputation: 77

heroku run rails console I get the following - syntax error, unexpected ':', expecting ')' (SyntaxError)

Here is my code.

 class ProductsController < ApplicationController
   before_action :set_product, only: [:show, :edit, :update, :destroy]
   respond_to :html, :xml, :json

  def index
    @products = Product.all
  end

 def show
 end

 def new
   @product = Product.new
 end

 def edit
 end

 def create
  @product = Product.new(product_params)
  @product.user = current_user
  @product.save


  respond_to do |format|
    if @product.save
      format.html { redirect_to @product, notice: 'Product was   successfully created.' }
      format.json { render :show, status: :created, location: @product }
    else
      format.html { render :new }
      format.json { render json: @product.errors, status: :unprocessable_entity }
    end
  end
end

  def update
    respond_to do |format|
      if @product.update(product_params) format.html { redirect_to @product, notice: 'Product was successfully updated.' }                                   format.json { render :show, status: :ok, location: @product }
      else
        format.html { render :edit }
        format.json { render json: @product.errors, status: :unprocessable_entity }
     end
   end
 end

 def destroy
    @product.destroy
      respond_to do |format|
        format.html { redirect_to products_url, notice: 'Product was successfully destroyed.' }
        format.json { head :no_content }
      end
 end

private
  # Use callbacks to share common setup or constraints between actions.
  def set_product
    @product = Product.find(params[:id])
  end

 # Never trust parameters from the scary internet, only allow the white list through.
  def product_params
    params.require(:product) .permit(:name, :permalink, :description, :price, :file)
  end
end

Here is the error message the full error message. The code works in development, I get the error with command heroku run rails console. In the console I created one user.

/app/app/controllers/products_controller.rb:75:syntax error, unexpected ':', expecting ')' (SyntaxError) ...rams.require(:product).permit(: name, : permalink, : descrip... ... ^

Upvotes: 0

Views: 281

Answers (1)

Zoran
Zoran

Reputation: 4226

You seem to have an extra space before your product_params permit method. Try writing it without the space, like so:

def product_params
  params.require(:product).permit(:name, :permalink, :description, :price, :file)
end

Hope that helps!

Upvotes: 1

Related Questions