D
D
Dmitry Amelchenko2014-03-04 11:20:52
Ruby on Rails
Dmitry Amelchenko, 2014-03-04 11:20:52

How to write a request in rails?

There is a standard model product (id, name), address 127.0.0.1/products
AND a model product_property (id, value, product_id), a one-to-many relationship
models/product.rb

class Product < ActiveRecord::Base
  has_many :product_properties
end

models/product_property.rb
class Product_property < ActiveRecord::Base
  belongs_to :product
end

config/routes.rb
Appname::Application.routes.draw do
  resources :products do
    resources :product_properties
  end

How to write a request correctly and what to add to the controller so that the view at 127.0.0.1/products/id/products_properties shows only the properties of a specific product?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Boris Penkovsky, 2014-03-07
@i1677960

Judging by the routes, your request will fall into the index ProductProperty action of the controller, the product identifier will be available there as params[: product_id], but then everything is simple
In the view, display @properties
And read all such tutorials)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question