⬆️ ⬇️

Easy way to get model fields in ActiveResource

If you tried to use REST, then you know that when connecting a resource through ActiveResource there is a problem in the absence of a resource schema.



As a result, an error occurred while displaying the scapold creation page of the object ( new.html.erb ). It would be nice to have at least an elementary list of model attribute fields.



The problem is easily fixed as follows:



 class ProductResource <ActiveResource :: Base

   def self.new (attributes = self.get ("new"))
     super (attributes)
   end

 end


')

At the same time, there is no need to change anything on the server side: the REST controller remains typical of Scapolds, and the resource routes are drawn up with the standard map.resources



Who else knows what ways to solve the problem of the lack of a scheme in ActiveResource? What are the ways to download it?

Source: https://habr.com/ru/post/62305/



All Articles