Note that there are some explanatory texts on larger screens.

plurals
  1. POproper way to setup facebook canvas url and routes in a rails app
    text
    copied!<p>I have an existing rails application to which i am adding a new controller to handle requests from a small facebook app (using the facebooker plugin) i am building. </p> <p>In the facebook app's config i set the canvas callback url to <a href="http://my.host.ip/fb/" rel="nofollow noreferrer">http://my.host.ip/fb/</a></p> <p>In a pure facebook application the url would leave off the /fb/ and the user would be directed to the app's home page. but since this is an existing application, i cannot do that.</p> <p>Now in my routes.rb i have:</p> <pre><code>map.connect '/fb/like/:id', :controller =&gt; 'facebook_app', :action =&gt; "like" map.connect '/fb/:category', :controller =&gt; 'facebook_app', :action =&gt; "index", :category =&gt; "default" </code></pre> <p>Ao when the user visits <a href="http://apps.facebook.com/my_app_name/" rel="nofollow noreferrer">http://apps.facebook.com/my_app_name/</a> facebook makes a call to <a href="http://my.host.ip/fb/" rel="nofollow noreferrer">http://my.host.ip/fb/</a> and that renders fine.</p> <p>On that page i have links to the "like" action:</p> <pre><code>&lt;%= link_to "like", :controller =&gt; "fb", :action =&gt; "like", :id =&gt; id %&gt; </code></pre> <p>Only problem is these get rendered as:</p> <p><a href="http://apps.facebook.com/my_app_name/fb/like/12345" rel="nofollow noreferrer">http://apps.facebook.com/my_app_name/fb/like/12345</a></p> <p>When what i want is:</p> <p><a href="http://apps.facebook.com/my_app_name/like/12345" rel="nofollow noreferrer">http://apps.facebook.com/my_app_name/like/12345</a></p> <p>See how the /fb/ is causing me grief?</p> <p>Is there a way around this? either some way in the routes definition to say that the /fb/ was only for incoming URLs? or some way in the url generator to omit the /fb/?</p> <p>I found one workaround… if I add this route above the existing "like" route:</p> <pre><code>map.connect '/like/:id', :controller =&gt; 'facebook_app', :action =&gt; "like" </code></pre> <p>Then that first route is what's used by the link_to url generator and the correct URL gets generated:</p> <p><a href="http://apps.facebook.com/my_app_name/like/12345" rel="nofollow noreferrer">http://apps.facebook.com/my_app_name/like/12345</a></p> <p>Which when clicked causes facebook to make this request to my app:</p> <p><a href="http://my.host.ip/fb/like/12345" rel="nofollow noreferrer">http://my.host.ip/fb/like/12345</a></p> <p>Which is matched by the original "like" route.</p> <p>I'd rather not have to do this for every action in my facebook controller though.</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