0

I'm following rails cast #263 for client side validations and am trying to make them come out onto the screen for my posts. Everything seemed fine so far, but when I go to posts new I get the error

ArgumentError in Posts#new
wrong number of arguments (3 for 2)
Extracted source (around line #1):
<%= form_for @post, :validate => true, :html => {:multipart => true} do |f| %>

here is a copy of my post _form

<%= form_for @post, :validate => true, :html => {:multipart => true} do |f| %>
  <% if @post.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>

      <ul>
      <% @post.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>
  <div class="field">
    <%= f.label :title %><br>
    <%= f.text_field :title %>
  </div>
  <div class="field">
  <%= f.file_field :image %>
  </div>
  <div class="field">
     <%= f.label :content %><br>
    <%= f.text_area :content %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

application.htm.erb file

<!DOCTYPE html>
<html>
<head>
  <title>Blog</title>
  <%= stylesheet_link_tag    "application", media: "all", "data-turbolinks-track" => true %>
  <%= javascript_include_tag "application", "rails.validations", "data-turbolinks-track" => true %>
  <%= csrf_meta_tags %>
  <%= favicon_link_tag 'favicon1.ico' %>

  <%= render 'layouts/nav' %>


</head>
<body>

<%= yield %>

</body>

<footer>
<%= render 'layouts/footer' %>
</footer>
<br>
</html>

post model

class Post < ActiveRecord::Base
  belongs_to :user
  has_many :comments
  mount_uploader :image, ImageUploader
  validates :title, presence: true,
                    length: { minimum: 5 }
  validates :content, presence: true,
  length: { minimum: 5 }
end

and my client_side_validations.rb file

# ClientSideValidations Initializer

# Uncomment to disable uniqueness validator, possible security issue
# ClientSideValidations::Config.disabled_validators = [:uniqueness]

# Uncomment to validate number format with current I18n locale
# ClientSideValidations::Config.number_format_with_locale = true

# Uncomment the following block if you want each input field to have the validation messages attached.
#
# Note: client_side_validation requires the error to be encapsulated within
# <label for="#{instance.send(:tag_id)}" class="message"></label>
#
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
  unless html_tag =~ /^<label/
    %{<div class="field_with_errors">#{html_tag}<label for="#{instance.send(:tag_id)}" class="message">#{instance.error_message.first}</label></div>}.html_safe
  else
    %{<div class="field_with_errors">#{html_tag}</div>}.html_safe
  end
end

anyone here know what the problem is and or why its happening? Did I miss or spell something wrong?

1 Answers1

0

Can you please tell which version of Rails you are using. ?

Because if your using Rails 4 then Client Side validation is outdated. You can check here

http://railscasts.com/episodes/263-client-side-validations?view=comments

and also if you go to the github page

https://github.com/bcardarella/client_side_validations

you can see that it says its no longer maintained.

Alternatively you can try using the CSV gem from this branch, by replacing the CSV line in your Gemfile by this

gem 'client_side_validations', github: "bcardarella/client_side_validations", :branch => "4-0-beta"

Not sure even if this will work though. Since its outdated.

Or you can check this gem out,

https://github.com/kalkov/rails4_client_side_validations

Its just a modified version of Client Side Validations

Nikhil Nanjappa
  • 6,454
  • 3
  • 28
  • 44