0

I have a javascript file that other people use on their site. It creates a button and loads a css file that is hosted on our server:

style.setAttribute('href', 'http://mysite.com/assets/some.css');

The user can call it in their site like so:

<script type="text/javascript" src="http://mysite.com/global.js"></script>

I want to give the user the ability to upload their own CSS file on my web app that will replace the one that I am setting in global.js.

Currently, I added a custom_css:binary column in the Users table that will hold the CSS file, but this requires the user to stay signed in on the site. I'm not sure if this is the right way to approach this or if there is a better way to do it. Also, what are some security risks to this approach?

I'm using RoR for the backend.

Any help would be great!

UPDATE 1

I'm able to store the uploaded JS file and load the custom CSS, but it's currently checking the current_user - this means the stylesheet will not be rendered for the users. How can I work around this?

rabid_zombie
  • 982
  • 2
  • 16
  • 32
  • Add CSS Element in Header: http://stackoverflow.com/questions/707565/how-do-you-add-css-with-javascript/6211716#6211716 – Stan Wiechers Apr 25 '13 at 21:03

1 Answers1

0

I was able to find the solution myself.

There are several ways to approach this:

  1. Add a query string to the JS src
  2. Scrape the page for a certain element that gets generated by your script

I opted for option 1. When I detect a dynamically generated query string, I send that over to the controller in the params hash and load the css file accordingly.

rabid_zombie
  • 982
  • 2
  • 16
  • 32