0

I have a model (OrderFilter) not tied to a database table which I use to pass filter parameters to the view. The model and view are considerably more complicated than below but I've stripped it down to the bare essentials.

class OrderFilter  
  attr_accessor :role, :draft, :submitted, :approved, :processed, :errors  
  def initialize(user_id)
    # @errors = []
  end
end

# Controller
def index
  @order_filter = OrderFilter.new(session[:user_id])
  respond_to do |format|
    format.html
  end
end

# View:    
  <%= select(:order_filter, :role, ['a','b','c'] )%>

All worked as expected until I added an array to pass errors to the view (@errors). Initialising the array in the constructor (ie. uncomment # @errors = []) produces ActionView::Template::Error (no implicit conversion of String into Integer) on the select tag line.

Any help would be appreciated - I've searched high and low and can't find anything similar!

2 Answers 2

1

I think it has to do with the fact that "errors" is used in rails to communicate validation specific errors from the model to the view. I guess the "select" tries to read those errors, and expects a different format... I guess simply by renaming the errors variable, your issue will be solved...

Sign up to request clarification or add additional context in comments.

1 Comment

Knew it had to be something simple! Thanks for the prompt response, Danny.
0

Or you can make your class more rails-friendly by including ActiveModel::Validations module. Which will handle all errors logic.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.