Forum: Ruby on Rails tiny mce - different options for different actions in same controller?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C925028bd49e1959ab209fb3e02fe0de?d=identicon&s=25 hading (Guest)
on 2008-10-24 11:37
(Received via mailing list)
Hi,

I'm using the current TinyMCE plugin for rails (V. 3.2.0.2-1). I want
to know if there is a way to use different options for the editor in a
single controller depending on the action invoked. I've tried re-
invoking the uses_tiny_mce declaration in the individual actions,
e.g.

def my_action
  self.class.uses_tiny_mce :options => {this actions options}
...

and also using separate uses_tiny_mce declarations at the top
with :only filters to discriminate between the actions, e.g.

uses_tiny_mce :only => [:edit_small], :options => {edit_small options}
uses_tiny_mce :only => [:edit_big], :options => {edit_big_options}

but neither of these approaches seem to work.

Thanks,
Howard
74198b06bc9e68739debfe6c23e070d3?d=identicon&s=25 Kieran P (Guest)
on 2008-10-24 11:57
(Received via mailing list)
Hello Howard,

I currently maintain the plugin at http://github.com/kete/tiny_mce
(which
looking at the version number appears to be the one you're using). If
thats
the one you use, then what you want to do isn't currently possible via
the
controller.

http://github.com/kete/tiny_mce/tree/master/lib/ti...

As you'll see in the link above, it sets an instance variable used later
in
the view helpers. The last declaration of uses_tiny_mce will overwrite
that
variable.

However, the view helpers can take a different set of options. So you
can do
something like this in application.html.erb:

if params[:action] == "edit_small"
  tiny_mce_init(edit_small_options)
elsif params[:action] == "edit_big"
  tiny_mce_init(edit_big_options)
else
  tiny_mce_init  # use whatever options specified in the controller
end

Having a look at it now, I see I missed a couple of places for passing
those
options (for example  include_tiny_mce_if_needed(edit_big_options) isn't
possible), so for now (until I get a chance to push some changes), to
stop
including tiny_mce unnessesarily, wrap the tiny_mce code in an
using_tiny_mce? conditional, like so

if using_tiny_mce?
  # the rest of the application.html.erb code above
end

Hope this helps.

Regards
Kieran
C925028bd49e1959ab209fb3e02fe0de?d=identicon&s=25 hading (Guest)
on 2008-10-24 14:43
(Received via mailing list)
Thank you, that will be helpful.

Howard
This topic is locked and can not be replied to.