ruby - how to rails one to one relationship? -


i new rails. please me how create rails 1 one relationship. have 2 table abc , pqr. in models have declared has_one:pqr in abc model , belongs_to:abc in pqr model. don't know how write view , controller "pqr".

you use

bin/rails generate controller pqr hello 

it generate controller file, view file, functional test file , helper view,. more information have @ this article.

  exists  app/controllers/   exists  app/helpers/   create  app/views/pqr   exists  test/functional/   create  test/unit/helpers/   create  app/controllers/pqr_controller.rb   create  test/functional/pqr_controller_test.rb   create  app/helpers/pqr_helper.rb   create  test/unit/helpers/pqr_helper_test.rb   create  app/views/pqr/hello.html.erb 

you can add contents used view, @ action hello in controller pqr_controller.rb

class pqrcontroller < applicationcontroller   def hello     @content = "hello world"   end end 

then if want other action , view corresponding later, show, add action in controller , generate corresponding view @ app/views/pqr/show.html.erb

class pqrcontroller < applicationcontroller   def hello     @content = "hello world"   end   def show     @contents = "test"   end end 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -