-1

I'm getting an error:

The provided regular expression is using multiline anchors (^ or $).  Did you mean to use \A and \z, or forgot to add the :multiline => true option? 

when loading only one page in my Rails application.

It highlights the model it's using saying the error is:

class Associate < Locations::Associate

This is the model:

class Associate < Locations::Associate

 # Returns an array of permissions which are valid at the associate level.
 #
 def self.associate_permissions
  ASSOCIATE_PERMISSIONS
 end

 # Generates an array of permission values that can be used in the new or edit
 # template.
 #
 def permission_list
   my_permissions = (permissions || '').split(/,/)
   list = []
   Associate.associate_permissions.each do |value|
     list << {:label => value[0], :value => value[1], :checked => my_permissions.include?    (value[1])}
   end
   list
 end

end

The controller:

class AssociatesController < ApplicationController
  def index
    @associates = Associate.paginate :order => 'code',
                                     :page => params[:page], :per_page => 50
    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @associates }
   end
 end

end

Can anyone tell me how to solve this error?

T0ny lombardi
  • 1,800
  • 2
  • 18
  • 35

2 Answers2

0

I am assuming that you are getting the error while rendering an index view.

Update the index action with

@associates = Associate.order('code').paginate(:page => params[:page], :per_page => 50)

instead of

@associates = Associate.paginate :order => 'code',
                                     :page => params[:page], :per_page => 50
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Kirti Thorat
  • 52,578
  • 9
  • 101
  • 108
0

I figured out my issue. I have a gem that runs most of my models. in the gems model I have:

class Locations::Associate < Locations::Database
  require 'digest'

  attr_accessible :code, :email, :include_on_reports, :name,
                  :permissions, :phone, :writer

  has_many :associate_branches, :dependent => :destroy

  validates :code, :presence => true, :uniqueness => true,
                   :format => { with: /^[A-Z]{3}\d{4}$/, on: :create }

.....
end

I had to change the regex to:

validates :code, :presence => true, :uniqueness => true,
                   :format => { with: /\A[A-Z]{3}\d{4}\z/, on: :create }

thanks for all the help.

T0ny lombardi
  • 1,800
  • 2
  • 18
  • 35
  • There is usually only one reason to use `\A` and `\z` in lieu of `$` and `$`. Don't know if its true in your case but here it is: Usually `^` and `$` are implied as they can match `\A` and `\z` in non-multiline mode. However, if also parseing a substring in another regex using for example, iterators (pointers) of the original string, `\A` and `\z` must be used because it is scoped to the segment. Not sure if this is in ruby. Typically boost regex in C++ use iterators to speed performance. –  Mar 24 '14 at 17:21