M
M
Michael2018-10-31 11:48:38
MongoDB
Michael, 2018-10-31 11:48:38

How to make a form work in rails with mongoid?

I'm trying to call back but something doesn't work:
Ruby 2.3.3
Rails 4.2
mongoid 5.2.1
haml
Gemfile

source 'https://rubygems.org'
ruby '2.3.3'

# core
gem 'rails', '4.2.0'
gem 'sass-rails'
gem 'sprockets'
gem 'compass-rails'
gem 'mongoid'
gem 'delayed_job_mongoid'
gem 'newrelic_rpm'
gem 'devise'
gem 'responders'
gem 'puma'

# front end & layouts
# gem 'bootstrap', '~> 4.0.0.alpha5'
# gem 'tether-rails'
gem 'bootstrap-sass'
gem 'turbolinks'
gem 'coffee-rails'
gem 'jquery-rails'
gem 'therubyracer'
gem 'money-rails'
gem "font-awesome-rails"
gem 'nested_form'
gem 'haml'

gem 'dropzonejs-rails'
# gem 'twitter-bootstrap-rails'
gem 'sanitize'
gem 'russian'
gem 'ckeditor', github: 'galetahub/ckeditor'
gem 'chosen-rails'
# gem 'galetahub-simple_captcha', require: 'simple_captcha'
gem 'simple_captcha', :git => 'git://github.com/Azdaroth/simple-captcha.git', :branch => 'rails-4'
gem "letter_opener"

gem 'kaminari'
gem 'kaminari-i18n'
gem 'kaminari-mongoid'
gem 'bootstrap-kaminari-views'
gem 'toastr-rails'

# uploader
gem 'mini_magick'
gem 'unicode_utils'
gem 'carrierwave'
gem 'carrierwave-mongoid'

Model:
callback.rb
class Callback
  include Mongoid::Document

  field :name, :type => String
  field :email, :type => String
  field :phone, :type => Integer
  field :comment, :type => String

end

Controller:
callbacks_controller.rb
class CallbacksController < ApplicationController

  def new
    @callback = Callback.new 
  end

  def create
    @callback = Callback.new(callback_params)

    if @callback.save
      redirect_to (session[:return_to] || :back), notice: 'Спасибо за заявку! Наши менеджеры скоро свяжутся с вами.'
    else
      render action: 'new'
    end
  end

private
  def callback_params
    params.require(:callback).permit(:name, :email, :phone, :comment)
  end

end

routes.rb
get '/callback' => 'callbacks#new', as: :custom_callbaks
  post '/callback' => 'callbacks#create', as: :custom_callbaks_create

View _header.html.haml
.callback
          %a.call{:href => "#openModal"} Заказать звонок
          #openModal.modal
            .modal-dialog
              .modal-content
                .modal-header
                  %h3.modal-title Заказать звонок
                  %a.close{:href => "#close", :title => "Close"} ×
                .modal-body
                  = form_for :callback, url: custom_callbaks_path do |f|
                    .wrap-call
                      .col-call
                        = f.label 'Ваше имя*'
                        = f.text_field :name, required: true
                      .col-call
                        = f.label 'E-mail'
                        = f.text_field :email
                      .col-call
                        = f.label 'Телефон *'
                        = f.text_field :phone, required: true
                      .col-call
                        = f.label 'Комментарий', for: :comment
                        = f.text_area :comment, id: 'comment'
                      .col-call 
                        = f.submit 'Оформить заявку'

All this produces the following error:
ArgumentError at /callback
wrong number of arguments (given 1, expected 5)
Screen:
http://i.prntscr.com/3riiXKqLShukWfzeAJbi6A.png
Console screen:
http://i.prntscr.com/JI2u2KfES92a8ogj_yo65Q.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
oh_shi, 2018-10-31
@mirbook

Change the name of the class, otherwise this one is called:
https://github.com/rails/rails/blob/master/actives...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question