Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top