Is there a standard way to get an ActiveRecord item within Ruby on Rails from a given URL? -


is there standard way activerecord item in ruby on rails given url? have data in external rdf database can query urls items in ruby on rails code. want hold of activerecord objects belonging these urls inside ruby on rails program. example of query results database:

"http://localhost:3000/data_files/5", "http://localhost:3000/assays/3",  "http://localhost:3000/assays/5" 

i know parse , call:

datafile.find(5) assays.find(3) assays.find(5) 

but thought there might standard bit of code this. can see have multiple types of object search for, , need right object type using id number.

on basic example should work.

def get_object_from_url url_string   class_string = url_string.split('/')[-2]   object_id = url_string.split('/')[-1]    class_string.camelize.constantize.find_by_id(object_id) end 

would require more complicated logic depending on url's.


Comments

Popular posts from this blog

angularjs - Redirect to a new template in angular js -

Oracle SQL. How to select specific IDs where value of columns specify criteria? -

Desktop Launcher for Python Script Starts Program in Wrong Path (Linux) -