This question have two parts:
- It is possible to load, or not, a specific Helper file depending on which platform are you using?
- How can I override a function in other helper file?
I want to load a helper file named MobileHelper when I detect a session using a mobile. In a desktop platform I don't want to load this file.
On the other side, I have a WelcomeHelper with a show_comments function. This MobileHelper have to change the logic of this show_comments function.
By now, I made a partial solution calling the mobile version function, with other name, inside the original function if it detects that you are using a mobile.
module WelcomeHelper
def show_comments
return mobile_show_comments if user_agent.mobile?
# original code
end
end
module MobileHelper
def mobile_show_comments
# mobile code
end
end
The final version I want to have is two equal named functions in two helper files and one of this files must be load only on mobile platforms