Hi Facebookers,
I have been working on a change to facebooker to allow facebook and
non-facebook apps to exist on the same code-base. I modified the url
rewriting in facebooker a bit so that it would continue to use the
facebook relative url when needed but not prepend the facebook app
name to controller paths that didn''t have anything to do with your
facebook app.
Here is the current problem:
Take for example a resource named sessions and ENV
[''FACEBOOKER_RELATIVE_URL_ROOT''] =
''facebook_app''. Sessions has
nothing to do with your facebook app yet as Facebooker is written
presently "sessions_path" will produce
"facebook_app/sessions/" even
if the sessions controller doesn''t call any of the facebooker
before_filters.
Part of the reason for this is that the url_writing methods add the
key :skip_relative_url_root to the options hash for the url_rewrite
method. It is assigned a boolean value and passed along to the
ActionController::UrlRewriter#rewrite_url method.
Unfortunately, rewrite_url cares about the existence of the key not
only its'' value.
def rewrite_url(path, options)
url = old_rewrite_url(path, options)
if ActionController::check_mode_and_base
unless options[:skip_relative_url_root]
url = url.gsub(@request.protocol + @request.host_with_port,
'''')
url = BASE_URL + url
end
end
url
end
Here is a slight change to the rewrite_url_with_facebooker method,
which deletes the :skip_relative_url_root key if it is true.
def rewrite_url_with_facebooker(*args)
options = args.first.is_a?(Hash) ? args.first : args.last
is_link_to_canvas=link_to_canvas?(@request.request_parameters,
options)
options[:skip_relative_url_root] ||= !is_link_to_canvas
options.delete(:skip_relative_url_root) if options
[:skip_relative_url_root] == true && !is_link_to_canvas
if is_link_to_canvas && !options.has_key?(:host)
options[:host] = "apps.facebook.com"
end
options.delete(:canvas)
rewrite_url_without_facebooker(*args)
end
Though this produced one failing test in the facebook rails
integration tests.
The "test_url_for_doesnt_include_url_root_when_not_linked_to_canvas"
failed but when i looked at the controller it was still testing for
facebook variables namely the before_filters. This was not the same
as having a controller that didn''t really have any knowledge of the
facebook portion of the app, which is what the test seemed to imply.
I created a NonFacebookController like so:
class NonFacebookController < ActionController::Base
def link_test
render :text=>''link''
end
def rescue_action(e) raise e end
end
And changed the routing to include a default path like so:
ActionController::Routing::Routes.draw do |map|
map.connect ''require_auth/:action'', :controller =>
"controller_which_requires_facebook_authentication"
map.connect ''require_install/:action'', :controller =>
"controller_which_requires_application_installation"
map.connect '':controller/:action/:id''
end
I changed the
"test_url_for_doesnt_include_url_root_when_not_linked_to_canvas" like
so:
def test_url_for_doesnt_include_url_root_when_not_linked_to_canvas
@controller = NonFacebookController.new
get :link_test,example_rails_params_including_fb.merge
(:fb_sig_in_canvas=>0,:canvas=>false)
assert !@response.body.match(/root/)
end
All tests pass again. Please let me know if this seems like a
reasonable approach. I am happy to bundle this into a diff if anyone
would like it added to the facebooker core.
Later,
Mark
def test_url_for_doesnt_include_url_root_when_not_linked_to_canvas
@controller = NonFacebookController.new
get :link_test,example_rails_params_including_fb.merge
(:fb_sig_in_canvas=>0,:canvas=>false)
assert !@response.body.match(/root/)
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://rubyforge.org/pipermail/facebooker-talk/attachments/20071220/d2021400/attachment.html