Christopher Bailey
2008-Mar-06 01:12 UTC
[Facebooker-talk] Setting :canvas => false for URL generation doesn''t always work?
I generate a lot of URL''s in my Facebook related code that point to our main site, not our FB app. My understanding was that the way to do this was to use ":canvas => false" as a parameter to url_for and link_to and so on. However, that doesn''t seem to generate the proper URL''s. The URL''s still point to apps.facebook.com (because they don''t have a host/are relative). Interestingly, if I use a named route, and pass :canvas=>false to it, then it generates the proper URL (and if I leave canvas param off or set to true, it sets it to apps.facebook.com, so it''s definitely taking it into account). I''m wondering if someone can comment on this more? I have a fix, but I''m not sure if it''s actually a fix, or just solving the symptom or improper use on my part, etc. What I did to fix it was change Facebooker''s UrlRewriter#link_to_canvas? (in facebook_url_rewriting.rb) to look like this: def link_to_canvas?(params, options) option_override = options[:canvas] if option_override == false # important to check for false. nil should use default behavior options[:only_path] = false RAILS_DEFAULT_LOGGER.debug "set options[:only_path] to false" return false end option_override || @request.parameters["fb_sig_in_canvas"] == "1" || @request.parameters[:fb_sig_in_canvas] == "1" end The pertinent change is that if they sent canvas to false, I add the "only_path" option and set it to false. I''m also seeing a problem related to this with the Publisher class, but I''ll bring that up separately, as it''s a different kind of issue. -- Christopher Bailey Cobalt Edge LLC http://cobaltedge.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/facebooker-talk/attachments/20080305/36171c9c/attachment.html
Mike Mangino
2008-Mar-06 01:43 UTC
[Facebooker-talk] Setting :canvas => false for URL generation doesn''t always work?
This is a problem that comes because the developer (me) doesn''t use url_for. I''ve used named routes only for more than a year now. What version of rails are you using? That''s probably the first thing we''ll need to track this down. Also, any sample code would be helpful, especially if you can make it fail in a test. Mike On Mar 5, 2008, at 7:12 PM, Christopher Bailey wrote:> I generate a lot of URL''s in my Facebook related code that point to > our main site, not our FB app. My understanding was that the way to > do this was to use ":canvas => false" as a parameter to url_for and > link_to and so on. However, that doesn''t seem to generate the > proper URL''s. The URL''s still point to apps.facebook.com (because > they don''t have a host/are relative). Interestingly, if I use a > named route, and pass :canvas=>false to it, then it generates the > proper URL (and if I leave canvas param off or set to true, it sets > it to apps.facebook.com, so it''s definitely taking it into account). > > > I''m wondering if someone can comment on this more? I have a fix, > but I''m not sure if it''s actually a fix, or just solving the symptom > or improper use on my part, etc. What I did to fix it was change > Facebooker''s UrlRewriter#link_to_canvas? (in > facebook_url_rewriting.rb) to look like this: > > > def link_to_canvas?(params, options) > option_override = options[:canvas] > if option_override == false # important to check for false. > nil should use default behavior > options[:only_path] = false > RAILS_DEFAULT_LOGGER.debug "set options[:only_path] to false" > return false > end > option_override || @request.parameters["fb_sig_in_canvas"] == > "1" || @request.parameters[:fb_sig_in_canvas] == "1" > end > > > The pertinent change is that if they sent canvas to false, I add the > "only_path" option and set it to false. > > > I''m also seeing a problem related to this with the Publisher class, > but I''ll bring that up separately, as it''s a different kind of issue. > > -- > Christopher Bailey > Cobalt Edge LLC > http://cobaltedge.com > _______________________________________________ > Facebooker-talk mailing list > Facebooker-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/facebooker-talk-- Mike Mangino http://www.elevatedrails.com
Michael Niessner
2008-Mar-06 02:08 UTC
[Facebooker-talk] Setting :canvas => false for URL generation doesn''t always work?
:canvas => true/false will not work in any version of rails if :only_path => true. The rails docs state that by default url_for sets :only_path => true. So if you wanted url_for to give you a full url and not a path you would have to do url_for(blah, :only_path => false). And if you wanted to use :canvas you''d have to do url_for(blah, :only_path => false, :canvas => true/false). Since canvas only correctly when :only_path => false, it might make sense to check if :canvas is not nil and then set :only_path => false. Although, that has the side effect of having something_path(:canvas => true/false) return a fully qualified url instead of a path. If it is decided that have something_path(:canvas => true/false) return a url instead of path is better than having to explicitly set :only_path => false when using url_for with :canvas then the method should probably look more like the following, since you will want the host to be added both when 1) linking to a facebook url from a non facebook page and 2) linking to a non facebook url from a facebook page. def link_to_canvas?(params, options) option_override = options[:canvas] options[:only_path] = false if !option_override.nil? if option_override == false # important to check for false. nil should use default behavior return false end option_override || @request.parameters["fb_sig_in_canvas"] == "1" || @request.parameters[:fb_sig_in_canvas] == "1" end Michael Niessner On Mar 5, 2008, at 7:43 PM, Mike Mangino wrote:> This is a problem that comes because the developer (me) doesn''t use > url_for. I''ve used named routes only for more than a year now. > > What version of rails are you using? That''s probably the first thing > we''ll need to track this down. Also, any sample code would be helpful, > especially if you can make it fail in a test. > > Mike > > > On Mar 5, 2008, at 7:12 PM, Christopher Bailey wrote: > >> I generate a lot of URL''s in my Facebook related code that point to >> our main site, not our FB app. My understanding was that the way to >> do this was to use ":canvas => false" as a parameter to url_for and >> link_to and so on. However, that doesn''t seem to generate the >> proper URL''s. The URL''s still point to apps.facebook.com (because >> they don''t have a host/are relative). Interestingly, if I use a >> named route, and pass :canvas=>false to it, then it generates the >> proper URL (and if I leave canvas param off or set to true, it sets >> it to apps.facebook.com, so it''s definitely taking it into account). >> >> >> I''m wondering if someone can comment on this more? I have a fix, >> but I''m not sure if it''s actually a fix, or just solving the symptom >> or improper use on my part, etc. What I did to fix it was change >> Facebooker''s UrlRewriter#link_to_canvas? (in >> facebook_url_rewriting.rb) to look like this: >> >> >> def link_to_canvas?(params, options) >> option_override = options[:canvas] >> if option_override == false # important to check for false. >> nil should use default behavior >> options[:only_path] = false >> RAILS_DEFAULT_LOGGER.debug "set options[:only_path] to false" >> return false >> end >> option_override || @request.parameters["fb_sig_in_canvas"] =>> "1" || @request.parameters[:fb_sig_in_canvas] == "1" >> end >> >> >> The pertinent change is that if they sent canvas to false, I add the >> "only_path" option and set it to false. >> >> >> I''m also seeing a problem related to this with the Publisher class, >> but I''ll bring that up separately, as it''s a different kind of issue. >> >> -- >> Christopher Bailey >> Cobalt Edge LLC >> http://cobaltedge.com >> _______________________________________________ >> Facebooker-talk mailing list >> Facebooker-talk at rubyforge.org >> http://rubyforge.org/mailman/listinfo/facebooker-talk > > -- > Mike Mangino > http://www.elevatedrails.com > > > _______________________________________________ > Facebooker-talk mailing list > Facebooker-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/facebooker-talk
Christopher Bailey
2008-Mar-06 02:21 UTC
[Facebooker-talk] Setting :canvas => false for URL generation doesn''t always work?
I figured that might be the case (devs only use named routes). Named routes are awesome, but simply not practical for our app (think thousands of routes). We are using Rails 1.2.3, and I will be moving up to Rails 2 when I can, but that is not a small task, and I was hoping to get the Facebook implementation done first (although the more I run into these things, the more I start to think about spiking on the Rails update). The behavior, at least as far as I can tell, actually makes sense. If you don''t specify the only_path = false aspect, it defaults to true as per Rails docs, so of course it''s not going to put the full host in there, and thus a relative path is going to resolve to apps.facebook.com. I''ll see if I can''t put a simple test case together and submit that so you have something. I''m wondering what other folks have seen who may be using url_for or link_to, if anyone is. If folks are doing Facebook only apps, then it''s something they won''t have come across, but for these apps that are their own site, as well as have the Facebook portion integrated into that same web app, it''s an issue. Thanks for discussing. On 3/5/08, Mike Mangino <mmangino at elevatedrails.com> wrote:> > This is a problem that comes because the developer (me) doesn''t use > url_for. I''ve used named routes only for more than a year now. > > What version of rails are you using? That''s probably the first thing > we''ll need to track this down. Also, any sample code would be helpful, > especially if you can make it fail in a test. > > Mike > > > > On Mar 5, 2008, at 7:12 PM, Christopher Bailey wrote: > > > I generate a lot of URL''s in my Facebook related code that point to > > our main site, not our FB app. My understanding was that the way to > > do this was to use ":canvas => false" as a parameter to url_for and > > link_to and so on. However, that doesn''t seem to generate the > > proper URL''s. The URL''s still point to apps.facebook.com (because > > they don''t have a host/are relative). Interestingly, if I use a > > named route, and pass :canvas=>false to it, then it generates the > > proper URL (and if I leave canvas param off or set to true, it sets > > it to apps.facebook.com, so it''s definitely taking it into account). > > > > > > I''m wondering if someone can comment on this more? I have a fix, > > but I''m not sure if it''s actually a fix, or just solving the symptom > > or improper use on my part, etc. What I did to fix it was change > > Facebooker''s UrlRewriter#link_to_canvas? (in > > facebook_url_rewriting.rb) to look like this: > > > > > > def link_to_canvas?(params, options) > > option_override = options[:canvas] > > if option_override == false # important to check for false. > > nil should use default behavior > > options[:only_path] = false > > RAILS_DEFAULT_LOGGER.debug "set options[:only_path] to false" > > return false > > end > > option_override || @request.parameters["fb_sig_in_canvas"] => > "1" || @request.parameters[:fb_sig_in_canvas] == "1" > > end > > > > > > The pertinent change is that if they sent canvas to false, I add the > > "only_path" option and set it to false. > > > > > > I''m also seeing a problem related to this with the Publisher class, > > but I''ll bring that up separately, as it''s a different kind of issue. > > > > -- > > Christopher Bailey > > Cobalt Edge LLC > > http://cobaltedge.com > > > _______________________________________________ > > Facebooker-talk mailing list > > Facebooker-talk at rubyforge.org > > http://rubyforge.org/mailman/listinfo/facebooker-talk > > > -- > Mike Mangino > http://www.elevatedrails.com > > >-- Christopher Bailey Cobalt Edge LLC http://cobaltedge.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/facebooker-talk/attachments/20080305/fa36a20f/attachment.html
Christopher Bailey
2008-Mar-06 04:07 UTC
[Facebooker-talk] Setting :canvas => false for URL generation doesn''t always work?
Michael, good point - I will likely at some point want to link directly into our FB app from the product as well (right now I only link to the FB app itself, so fairly straight forward). Thanks! On 3/5/08, Michael Niessner <mniessner at elevatedrails.com> wrote:> > :canvas => true/false will not work in any version of rails > if :only_path => true. The rails docs state that by default url_for > sets :only_path => true. So if you wanted url_for to give you a full > url and not a path you would have to do url_for(blah, :only_path => > false). And if you wanted to use :canvas you''d have to do > url_for(blah, :only_path => false, :canvas => true/false). > > Since canvas only correctly when :only_path => false, it might make > sense to check if :canvas is not nil and then set :only_path => false. > Although, that has the side effect of having something_path(:canvas => > true/false) return a fully qualified url instead of a path. > > If it is decided that have something_path(:canvas => true/false) > return a url instead of path is better than having to explicitly > set :only_path => false when using url_for with :canvas then the > method should probably look more like the following, since you will > want the host to be added both when 1) linking to a facebook url from > a non facebook page and 2) linking to a non facebook url from a > facebook page. > > > def link_to_canvas?(params, options) > option_override = options[:canvas] > > options[:only_path] = false if !option_override.nil? > > if option_override == false # important to check for false. nil > should use default behavior > > return false > end > option_override || @request.parameters["fb_sig_in_canvas"] => "1" || @request.parameters[:fb_sig_in_canvas] == "1" > end > > > Michael Niessner > > > On Mar 5, 2008, at 7:43 PM, Mike Mangino wrote: > > > This is a problem that comes because the developer (me) doesn''t use > > url_for. I''ve used named routes only for more than a year now. > > > > What version of rails are you using? That''s probably the first thing > > we''ll need to track this down. Also, any sample code would be helpful, > > especially if you can make it fail in a test. > > > > Mike > > > > > > On Mar 5, 2008, at 7:12 PM, Christopher Bailey wrote: > > > >> I generate a lot of URL''s in my Facebook related code that point to > >> our main site, not our FB app. My understanding was that the way to > >> do this was to use ":canvas => false" as a parameter to url_for and > >> link_to and so on. However, that doesn''t seem to generate the > >> proper URL''s. The URL''s still point to apps.facebook.com (because > >> they don''t have a host/are relative). Interestingly, if I use a > >> named route, and pass :canvas=>false to it, then it generates the > >> proper URL (and if I leave canvas param off or set to true, it sets > >> it to apps.facebook.com, so it''s definitely taking it into account). > >> > >> > >> I''m wondering if someone can comment on this more? I have a fix, > >> but I''m not sure if it''s actually a fix, or just solving the symptom > >> or improper use on my part, etc. What I did to fix it was change > >> Facebooker''s UrlRewriter#link_to_canvas? (in > >> facebook_url_rewriting.rb) to look like this: > >> > >> > >> def link_to_canvas?(params, options) > >> option_override = options[:canvas] > >> if option_override == false # important to check for false. > >> nil should use default behavior > >> options[:only_path] = false > >> RAILS_DEFAULT_LOGGER.debug "set options[:only_path] to false" > >> return false > >> end > >> option_override || @request.parameters["fb_sig_in_canvas"] => >> "1" || @request.parameters[:fb_sig_in_canvas] == "1" > >> end > >> > >> > >> The pertinent change is that if they sent canvas to false, I add the > >> "only_path" option and set it to false. > >> > >> > >> I''m also seeing a problem related to this with the Publisher class, > >> but I''ll bring that up separately, as it''s a different kind of issue. > >> > >> -- > >> Christopher Bailey > >> Cobalt Edge LLC > >> http://cobaltedge.com > >> _______________________________________________ > >> Facebooker-talk mailing list > >> Facebooker-talk at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/facebooker-talk > > > > -- > > Mike Mangino > > http://www.elevatedrails.com > > > > > > _______________________________________________ > > Facebooker-talk mailing list > > Facebooker-talk at rubyforge.org > > http://rubyforge.org/mailman/listinfo/facebooker-talk > >-- Christopher Bailey Cobalt Edge LLC http://cobaltedge.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/facebooker-talk/attachments/20080305/8f0488f0/attachment-0001.html
Mike Mangino
2008-Mar-06 04:23 UTC
[Facebooker-talk] Setting :canvas => false for URL generation doesn''t always work?
If you find yourself always setting only_path to false, you can always set this as a default_url_option. We should definitely add that to the docs. Mike On Mar 5, 2008, at 10:07 PM, Christopher Bailey wrote:> Michael, good point - I will likely at some point want to link > directly into our FB app from the product as well (right now I only > link to the FB app itself, so fairly straight forward). Thanks! > > On 3/5/08, Michael Niessner <mniessner at elevatedrails.com> > wrote: :canvas => true/false will not work in any version of rails > if :only_path => true. The rails docs state that by default url_for > sets :only_path => true. So if you wanted url_for to give you a full > url and not a path you would have to do url_for(blah, :only_path => > false). And if you wanted to use :canvas you''d have to do > url_for(blah, :only_path => false, :canvas => true/false). > > Since canvas only correctly when :only_path => false, it might make > sense to check if :canvas is not nil and then set :only_path => false. > Although, that has the side effect of having something_path(:canvas => > true/false) return a fully qualified url instead of a path. > > If it is decided that have something_path(:canvas => true/false) > return a url instead of path is better than having to explicitly > set :only_path => false when using url_for with :canvas then the > method should probably look more like the following, since you will > want the host to be added both when 1) linking to a facebook url from > a non facebook page and 2) linking to a non facebook url from a > facebook page. > > > def link_to_canvas?(params, options) > option_override = options[:canvas] > > options[:only_path] = false if !option_override.nil? > > if option_override == false # important to check for false. nil > should use default behavior > > return false > end > option_override || @request.parameters["fb_sig_in_canvas"] => "1" || @request.parameters[:fb_sig_in_canvas] == "1" > end > > > Michael Niessner > > > On Mar 5, 2008, at 7:43 PM, Mike Mangino wrote: > > > This is a problem that comes because the developer (me) doesn''t use > > url_for. I''ve used named routes only for more than a year now. > > > > What version of rails are you using? That''s probably the first thing > > we''ll need to track this down. Also, any sample code would be > helpful, > > especially if you can make it fail in a test. > > > > Mike > > > > > > On Mar 5, 2008, at 7:12 PM, Christopher Bailey wrote: > > > >> I generate a lot of URL''s in my Facebook related code that point to > >> our main site, not our FB app. My understanding was that the way > to > >> do this was to use ":canvas => false" as a parameter to url_for and > >> link_to and so on. However, that doesn''t seem to generate the > >> proper URL''s. The URL''s still point to apps.facebook.com (because > >> they don''t have a host/are relative). Interestingly, if I use a > >> named route, and pass :canvas=>false to it, then it generates the > >> proper URL (and if I leave canvas param off or set to true, it sets > >> it to apps.facebook.com, so it''s definitely taking it into > account). > >> > >> > >> I''m wondering if someone can comment on this more? I have a fix, > >> but I''m not sure if it''s actually a fix, or just solving the > symptom > >> or improper use on my part, etc. What I did to fix it was change > >> Facebooker''s UrlRewriter#link_to_canvas? (in > >> facebook_url_rewriting.rb) to look like this: > >> > >> > >> def link_to_canvas?(params, options) > >> option_override = options[:canvas] > >> if option_override == false # important to check for false. > >> nil should use default behavior > >> options[:only_path] = false > >> RAILS_DEFAULT_LOGGER.debug "set options[:only_path] to > false" > >> return false > >> end > >> option_override || @request.parameters["fb_sig_in_canvas"] => >> "1" || @request.parameters[:fb_sig_in_canvas] == "1" > >> end > >> > >> > >> The pertinent change is that if they sent canvas to false, I add > the > >> "only_path" option and set it to false. > >> > >> > >> I''m also seeing a problem related to this with the Publisher class, > >> but I''ll bring that up separately, as it''s a different kind of > issue. > >> > >> -- > >> Christopher Bailey > >> Cobalt Edge LLC > >> http://cobaltedge.com > >> _______________________________________________ > >> Facebooker-talk mailing list > >> Facebooker-talk at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/facebooker-talk > > > > -- > > Mike Mangino > > http://www.elevatedrails.com > > > > > > _______________________________________________ > > Facebooker-talk mailing list > > Facebooker-talk at rubyforge.org > > http://rubyforge.org/mailman/listinfo/facebooker-talk > > > > > -- > Christopher Bailey > Cobalt Edge LLC > http://cobaltedge.com-- Mike Mangino http://www.elevatedrails.com