I am getting the following error while i am submitting the form.
Error:
ActiveRecord::MultiparameterAssignmentErrors in HomesController#savemagazines
1 error(s) on assignment of multiparameter attributes
Rails.root: C:/Site/library_management1
Application Trace | Framework Trace | Full Trace
app/controllers/homes_controller.rb:85:in `new'
app/controllers/homes_controller.rb:85:in `savemagazines'
The below are my code snippets.
views/homes/magazines.html.erb:
<% if current_user %>
<div class="totaldiv">
<div class="navdiv"><span>Purchase Magazines</span> <span>Logged in as <%= current_user.email %></span></div>
<div class="wrapper">
<div id="leftsidebtn">
<ul>
<li><a href="/homes/issuebooks">Book issue</a></li>
<li><a href="/homes/availablebooks">Books Available</a></li>
<li><a href="/homes/magazines">Magazines Purchase</a></li>
<li><a href="/sessions/removeuser">Log Out</a></li>
</ul>
</div>
</div>
<div class="restdiv" id="ex3" >
<center>
<div class="container">
<%= form_for :magazines,:url => {:action => 'savemagazines'} do |f| %>
<p>
<label for="mg_name">Enter Magazine Name:</label>
<%= f.select(:mag_name,options_for_select([['Business India ','Business India'],['Business Today ','Business Today '],['Forbes India ','Forbes India '],['Time magazine Asia ','Time magazine Asia '],['Electronics For You','Electronics For You']],selected: "magazine"), { include_blank: true }) %>
</p>
<p>
<label for="mag_title">Enter Magazine Title</label>
<%= f.text_field :mag_title,placeholder:"Enter magazine title" %>
</p>
<p>
<%= f.check_box :cd_dvd,{},true,false %> CD/DVD
</p>
<p>
<label for="purchase">Purchase Date</label>
<%= f.date_select :purchased_on %>
</p>
<p>
<%= f.submit "submit",:class => "btn btn-success" %>
</p>
<% end %>
</div>
</center>
</div>
</div>
<% end %>
controller/homes_controller.rb
class HomesController < ApplicationController
before_filter :authenticate_admin!,only: [:admin]
def index
end
def admin
end
def managebooks
@books=Book.new
if params[:id]
@books=Book.find(params[:id])
@book=Book.all
end
end
def savebooks
@books=Book.new(params[:books])
if @books.save
flash[:notice]="Data has submitted successfully"
flash[:color]="valid"
redirect_to :action => 'managebooks',:id => @books.id
else
flash[:notice]="Data couldnot submitted successfully"
flash[:color]="invalid"
render 'managebooks'
end
end
def remove
@books=Book.find(params[:id])
@books.destroy
end
def books
end
def showbooks
@books=Book.all
end
def searchbooks
@books=Book.all
end
def member
@users=User.new
end
def registration
@users=User.new
end
def savedata
@users=User.new(params[:users])
if @users.save
flash[:notice]="Data has submitted successfully"
flash[:color]="valid"
redirect_to :action => 'member'
else
flash[:notice]="Data could not submitted successfully"
flash[:color]="invalid"
render 'registration'
end
end
def issuebooks
@issues=Issue.new
end
def savebooks
@issues=Issue.new(params[:issues])
if @issues.save
flash[:notice]="information has saved successfully"
flash[:color]="valid"
redirect_to :action => 'member'
else
flash[:notice]="Data couldnot saved"
flash[:color]="invalid"
render 'issuebooks'
end
end
def availablebooks
@books=Book.all
end
def userissues
@issues=Issue.all
end
def magazine
@magazines=Magazine.new
end
def savemagazines
@magazines=Magazine.new(params[:magazines])
if @magazines.save
flash[:notice]="Data submitted successfully"
flash[:color]="valid"
redirect_to :action => "member"
else
flash[:notice]="Data could not saved"
flash[:color]="invalid"
render 'magazines'
end
end
end
Please check my code and let me to know where i did the mistake and solution as well.
Aucun commentaire:
Enregistrer un commentaire