City table fields
create_table "cities", force: :cascade do |t| t.string "name" Order table fields
create_table "orders", force: :cascade do |t| t.integer "count" t.integer "first_city_id" Model Order
class Order < ActiveRecord::Base belongs_to :city, inverse_of: :city end City model
class City < ActiveRecord::Base has_many :orders, inverse_of: :order end Working data output from Order to view
<% @order.each do |orders| %> <p> <%= orders.count %> </p> <% end %> Method in controller
def edit @orders= Order.all @order=Order.where(:user_id == current_user) end How to get the name value from the Сity table, if the first_city_id in the Order table contains the id of the desired entry from the City table
belongs_to :citywork at all?city_idin this table, I do not see. - D-sideCity.find(order.first_city_id)- anoamfirst_city_idfield, which stores the id of the city table. You need to access the fields of the city table with the specified id infirst_city_id. - fis