im using ruby on rails , mysql hold database. i'm struggling understand how take information database , use in html page (that display).
for instance, if in database there table called users. how display user names (ie select names users) in html page (in views folder in rails app)?
i've started learning stuff sorry if trivial question! i'm not understanding of explanations on web.
thank you!
in rails have models interacts database. if want connect users table should create model.
class user < activerecord::base def self.names user.select('name') end end and create view should have controller can have index action:
class usercontroller < applicationcontroller def index @names = user.names end end in views folder can have users folder index.html.erb
in html file can access @names , iterate on them , display names.
you have define route in route.rb
resources :user and access link /users
you can refer rails tutorial: http://www.tutorialspoint.com/ruby-on-rails/
Comments
Post a Comment