you could create an create_css.rb file, place it in the lib/
directory,
and call it into any place where you want to use this
method.
so you could do something like:
(UNTESTED CODE)
***** lib/create_css.rb ******
module CreateCss
# btw, this statement (file.open) returns nil
def make_css(filename, css_content)
File.open(RAILS_ROOT + 'public/stylesheets' +
filename, 'w') { |f|
f.puts css_content }
end
end
and then, where ever in the app you want to do this (you
could probably
even create the css_content with some form, and retrive it
as params, or
whatever) just call the make_css method, and pass it the
correct
parameters.
you'll need to include the module, however.
example:
(UNTESTED CODE)
---------------------------------------------------------
require 'create_css.rb' # includes the file
class SomeArbitraryController
include CreateCss # includes the specific module
...
...
# here you want to create the file:
def someaction
.... # do some stuff
make_css("a_new_css_file",
params[:content_of_file])
... # continue doing some stuff
end
end
------------------------------------------------------------
----
and walla! you should get a new file in your public folder:
public/stylesheets/a_new_css_file.css
and if you opened it and looked at the content, it would
contain the
content of params[:content_of_file].
cheers,
--shai
--
Posted via http://www.ruby-forum.com
/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk googlegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe googlegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
|