Using structs in Ruby on Rails gives dynamic constant assignment (SyntaxError)

The error explains what the problem is – you have a constant being assigned in a context that’s too dynamic – i.e. inside the index method.

The solution is to define it outside:

DashItem = Struct.new(:name, :amount, :moderated)
def index
  @dashboard_items = []
  ...

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)