Undefined Method Pluralize for Main:Object

undefined method pluralize for main:Object

The helpers aren't included by default in the console. You can include them first and it'll work:

>> include ActionView::Helpers::TextHelper
>> pluralize(1, 'person')
# => "1 person"

Or, you can use the helper object which Rails gives you in the console:

>> helper.pluralize(1, 'person')
# => "1 person"

Undefined method 'pluralize' for #Controller

If you don't want to use view helpers, then you can use String#pluralize:

"customer".pluralize(@imported_customers.size)

If you want to use view helpers then you should include the respective helper as another answers or just use ActionView::Rendering#view_context:

view_context.pluralize(@imported_customers.size, "customer")

Why can't I use the pluralize method in rails console?

The pluralize method used in Rails views is defined in ActionView::Helpers::TextHelper. To use it in rails console you need to include it

$ rails console
2.3.3 :008 > include ActionView::Helpers::TextHelper
2.3.3 :009 > pluralize 2, 'man'
=> "2 men"

or call them through the helper variable

$ rails console
2.3.3 :0010 > helper.pluralize(2, 'man')
=> "2 men"

undefined method `nearest_larger' for main:Object

I think your main problem is a syntax error in your method which causes it not to be defined, so when you try to call it later it is not found.

The cause of the syntax error is the use of braces {} instead of brackets [] to access keys inside a hash.

Do not be confused by perl in this respect.

Accessing a hash value is different

in perl: some_hash{a_key}
in ruby: some_hash[a_key]

This may seem strange, since both use braces for hash literals:

Assigning an empty hash literal is the same

in perl: some_hash = {}
in ruby: some_hash = {}

Can't get pluralize/singularize working with ActiveSupport::Inflector (in irb)

Access to #pluralize without adding new methods to the String class:

require 'active_support/inflector'
ActiveSupport::Inflector.pluralize('test')
#=> "tests"

For String class:

require 'active_support/core_ext/string'
"test".pluralize
#=> "tests"

which actually calls ActiveSupport::Inflector.pluralize underneath:

def pluralize
ActiveSupport::Inflector.pluralize(self)
end

Trying to use validations with local variables

EDITED

In your UsersController in new action update as below

class UsersController < ApplicationController
def new
@user = User.new
end
end

and in your views/users/_form.html.erb file form do the below code

<%= form_for(@user) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

Número de Empregado: <br>
<%= f.number_field :NumeroEmpregado %><br>

Primeiro e Último Nome: <br>
<%= f.text_field :nome %><br>

Password: <br>
<%= f.password_field :password %><br>

Confirmação Password: <br>
<%= f.password_field :password_confirmation %><br>

<%= f.submit "Submit" %>

<% end %>

parse_resource returned undefined method `ParseResource' for main:Object

Your class name syntax is wrong, instead of:

class Venue < ParseResource:Base

you should write

class Venue < ParseResource::Base


Related Topics



Leave a reply



Submit