Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ok so here is another way to do it... JQuery and Json....</p> <p>So use directly used a controller like your user controller or whatever information you want to put in your widget, in my example, some information on companies.</p> <p>so add a method widget in your controller like:</p> <pre><code>def widget @company = Company.find(params[:id]) @logo_url = @company.logo_url(:mini) respond_to do |format| format.json { render :json =&gt; {:company =&gt; @company, :url =&gt; @logo_url}, :callback =&gt; params[:jsoncallback] } end end </code></pre> <p>In your routes.rb you should then have something similar to this:</p> <pre><code>resources :public_company_profiles do get :widget, on: :member end </code></pre> <p>then the JQuery parts making your html code from your JSON informations the third party website will use: First the script to add the jquery then the actual jquery request.</p> <pre><code>&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"&gt;&lt;/script&gt; &lt;script&gt; $.getJSON("http://www.yourwebsite.com/yourcontroller/ID/widget?jsoncallback=?", function(data) { var logo_url = "http://www.yourwebsite.com" + data.url; $("#logo img").attr('src',logo_url); $("#logo img").attr('alt',data.company.name); $("#name").html(data.company.name); $("#desc").html(data.company.description); }); &lt;/script&gt; </code></pre> <p>Then it works baby ! (dont forget to put the and stuff around the jQuery documentation here: api.jquery.com/html)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload