ruby on rails - Pass XML value from one page other page -
i want pass xml value 1 page in better way.
i getting xml value api:
<hotelist> <hotel> <hotelid>109</hotelid> <hotelname>hotel sara</hotelname> <location>uk,london</location> </hotel> <hotel> <hotelid>110</hotelid> <hotelname>radha park</hotelname> <location>uk,london</location> </hotel> <hotel> <hotelid>111</hotelid> <hotelname>hotel green park</hotelname> <location>chennai,india</location> </hotel> <hotel> <hotelid>112</hotelid> <hotelname>hotel mauria</hotelname> <location>paris,france</location> </hotel> </hotelist>
i want pass 1 hotel:
<hotel> <hotelid>112</hotelid> <hotelname>hotel mauria</hotelname> <location>paris,france</location> </hotel>
to next page.
i using nokogiri gem parsing xml. api next call have pass 1 hotel next page. best method?
note: sample. there lot of information bound hotel including available room, discount , on.
so far i'm getting this, searching hotels through third party service, , displaying list. after user clicks on item displaying detail info hotel.
the easiest way having api endpoint, can provide detail information specific hotel id. guess you're dealing bad api , that's not case.
there couple of other options (ordered complexity level):
there not data , should fit simple request, can encode respective hotel information url parameter detail page. assuming have set resourcefull routing , have parsed xml
@hotels
array of hotel models/structs or like:<% @hotels.each |hotel| %> <% # generates <a href=/hotels/112?hotelname=hotel+mauria&location=paris%2c+france'>hotel mauria</a> <%= link_to hotel.hotelname hotel_path(hotel.hotelid, hotelname: hotel.hotelname, location: hotel.location) %> <% end %>
encode info respective hotel dom elements data-attributes:
<div class="hotel" data-id="112" data-hotel-name="mauria" ... />
then render detail page on client side without server entirely subscribing click event, reading info stored in respective data attributes , replace list detail div.
if third party api public move search problem entirely client.
introduce caching of search requests on server. pick hotel cache id. saving doing third party requests rails app, weak spot of rails if deployed on typical multi-process server.
the simplest way of doing this, storing last search result in user session, memory heavy. if can expect hotel information not change frequently, cache query parameters. use smart caching store redis , index entire hotel information, performing search on cache , in case of cache miss hit third party api. remember, caching easy, expiring hard.
"everyone should using low level caching in rails" interesting implementing cache.
Comments
Post a Comment