Field name with "-"

Hello.

I’m tryes to write webGUI for application’s database. This application
uses pre-defined field names, for i.e. “session-timers” and I can’t
change its.

In the users.rb writes:

def index
@sipusers=User.all
end

In the index.html.erb:

<% @users.each do |user| %>
<%=h user[“session-timers”]%>
<%end%>

It’s work fine but servers output:

Exception occurred during reader method compilation.
Maybe session-timers is not a valid Ruby identifier?
/usr/lib64/ruby/gems/1.9.1/gems/activerecord-2.3.8/lib/active_record/attribute_methods.rb:1:
syntax error, unexpected ‘-’, expecting ‘;’ or ‘\n’
def session-timers; missing_attribute(‘se…
^
/usr/lib64/ruby/gems/1.9.1/gems/activerecord-2.3.8/lib/active_record/attribute_methods.rb:1:
syntax error, unexpected keyword_end, expecting $end
…tributes[‘session-timers’]; end
… ^
Exception occurred during reader method compilation.
Maybe session-timers is not a valid Ruby identifier?
/usr/lib64/ruby/gems/1.9.1/gems/activerecord-2.3.8/lib/active_record/attribute_methods.rb:1:
syntax error, unexpected ‘-’, expecting ‘;’ or ‘\n’
def session-timers=(new_value);write_attr…
^
/usr/lib64/ruby/gems/1.9.1/gems/activerecord-2.3.8/lib/active_record/attribute_methods.rb:1:
syntax error, unexpected keyword_end, expecting $end
…session-timers’, new_value);end
… ^
Exception occurred during reader method compilation.
Maybe session-timers is not a valid Ruby identifier?
/usr/lib64/ruby/gems/1.9.1/gems/activerecord-2.3.8/lib/active_record/attribute_methods.rb:1:
syntax error, unexpected ‘-’, expecting ‘;’ or ‘\n’
def session-timers?; query_attribute(‘session-timers’); end
^
/usr/lib64/ruby/gems/1.9.1/gems/activerecord-2.3.8/lib/active_record/attribute_methods.rb:1:
syntax error, unexpected keyword_end, expecting $end
def session-timers?; query_attribute(‘session-timers’); end
^

  1. How can I remove this errors? Maybe ActiveRecord can create alias for
    any name?

  2. How can I use helpers (.text_field. .label and etc) for inserting
    data from web page?

Thanks for answers.

def index
@sipusers=User.all
end

Must read

@users=User.all

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs