So I have this form in my books view, which shows a select box to choose if a boolean value is either true or false.
But when I submit it, it does not change the boolean value to true, if I select so.
This is my books scheme basicly:
create_table "books", force: true do |t|
t.string "name"
t.integer "user_id"
t.boolean "oppetool", default: false
t.datetime "created_at"
t.datetime "updated_at"
t.integer "count", default: 0
end
Why is it not changing the boolean value for my entry?
My view:
<% provide(:title, "Submit a book") %>
<b align="center">Enter the name of a book you want to add into the database and then press 'Submit!'</b>
<%= form_for(@book) do |f| %>
<div class="forms">
<%= f.text_field :name, placeholder: "Type what you want to say...", autofocus: true %>
<%= f.check_box(:oppetool, {}, "True", "False") %>
<%= f.submit 'Submit!' %>
</div>
<% end %>
Books controller:
class BooksController < ApplicationController
before_action :signed_in_user, only: [:index,:edit,:update, :destroy]
before_action :admin_user, only: :destroy
before_action :set_book, only: [:show, :edit, :update, :destroy]
def index
@books = Book.all
end
def show
@book = Book.find(params[:id])
end
def new
@book = current_user.books.build
end
def create
@book = current_user.books.build(book_params)
if @book.save
flash[:success] = "Book listed!"
redirect_to books_path
else
flash[:success] = "Did you leave a field empty? All fields must be filled before we can accept the review!"
render new_book_path
end
end
def edit
end
def update
end
def destroy
end
# Private section
private
def book_params
params.require(:book).permit(:name, :user_id)
end
def user_params
params.require(:user).permit(:name, :email, :password, :password_confirmation)
end
def admin_user
redirect_to(root_url) unless current_user.admin?
end
# Redirecting not logged in user etc.
def signed_in_user
unless signed_in?
store_location
redirect_to '/sessions/new', notice: "Please sign in!"
end
end
end