0

I am creating an auction website and I get an error when I run a command to create a new auction.

The model is simple: class Auction < ActiveRecord::Base has_many :bets has_many :profiles, :through => :bets

and etc.

The controller: `

class AuctionsController < ApplicationController

def new @auction = Auction.new end

def create

@auction = Auction.new(auction_params)

if @auction.save

 redirect_to(:action => 'index')

else

 render('new')

end

end

private

def auction_params

 params.require(:auction_email).permit(:auction_description, :auction_location, :auction_deadline, :auction_title, bets_attributes: [ :bet_size], )

end
end

The new.html.erb has form in this way:

<%= form_for(:auction, :url => {:action => 'create'}) do |f| %>
<%= f.text_field(:auction_title) %>

and so on for every entry.

The error message is:

ActionController::ParameterMissing in AuctionsController#create param not found: auction_email

I have been trying to solve it with "if params[:status]", but it returns an empty form and database remains empty.

Rails version 4.0.2

1 Answer 1

3

Use this

def auction_params    
 params.require(:auction).permit(:auction_email,:auction_description, :auction_location, :auction_deadline, :auction_title, bets_attributes: [ :bet_size], )
end

Assuming that Auction is your model. params.require argument should be :auction(:modelname) and in permit method you pass the atrributes like :auction_email(:attributename) that you would like to insert/update in database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.