当前位置: 动力学知识库 > 问答 > 编程问答 >

tinymce uninitialized constant AppConfig in rails 3.1?

问题描述:

I'm learning Rails as I go, and have been put on a project to update an existing site from Rails 2 to Rails 3.1.1. The app uses tinymce to allow an admin to edit several parts of the site's content. In our upgraded project, when I click this edit link the result is

Routing Error

ActionController::RoutingError (uninitialized constant Admin::ContentController::AppConfig):

app/controllers/admin/content_controller.rb:4:in `<class:ContentController>'

app/controllers/admin/content_controller.rb:1:in `<top (required)>'

I have searched all over the internet for help but this is unfortunately a somewhat generic name for a variable I guess? The project is using the gem, tinymce-rails, which I -think- is the correct option for rails 3.1. All I am trying to find out here is what is the root problem, so I know what part of the application needs to be updated so at least the page will load, even if there are more issues I need to fix afterwards...

I verified all of the steps from https://github.com/sandipransing/rails_tiny_mce#readme seem to be implemented (though that says rails 3.0, so I also looked over https://github.com/spohlenz/tinymce-rails)... Here's the code in the content controller that throws the error:

class Admin::ContentController < ApplicationController

before_filter :require_admin_login

uses_tiny_mce(:options => AppConfig.freysmile_options, :only => [:referral_center, :great_review_tips, :faq, :badge_assignment_mail, :point_assignment_mail, :add_referral_mail, :patient_invitation_mail])

The project seems to have tinymce-rails in the gemfile and also the plugins folder - it also has all of the plugins that are listed as being required on the first github link.

(Side note: Unfortunately this is a site made by someone else, given to our consulting boss who is not working with the original creator, and now my fiancee and myself are learning by updating this, so it is built in ways I would probably not have gone, but we do not have time for a complete redo.) Thanks for reading my question!

网友答案:

The uses_tiny_mce method is from another gem that is not compatible with rails > 3.1. You want to remove that method from any of your controllers and follow the instructions on the tinymce-rails readme. The tinymce-rails gem simply adds the tinymce javascript to your asset pipeline in rails-3.1+.

I don't know where the AppConfig.freysmile_options comes from. Search your app for 'freysmile'.

Here's how I'm using tinymce-rails with a 3.1.3 app:

Gemfile:

gem 'tinymce-rails'

application.js

//= require tinymce-jquery

views/shared/_mce.html.erb

<div id="form_content">
  <h3><%= f.label :content %></h3>
  <%= f.text_area :content, :cols => '100', :rows => '50', :class => 'mce' %>
</div>

<script type="text/javascript">
  $(function() {
    $('.mce').tinymce({
      width: 1000,
      theme: 'advanced',
      theme_advanced_toolbar_location: 'top',
      theme_advanced_buttons1: 'bold, italic, underline, strikethrough, justifyleft, justifycenter, justifyright, justifyfull, bullist, numlist, outdent, indent, cut, copy, paste, undo, redo, link, unlink, image, cleanup, code, removeformat, help',
      theme_advanced_buttons2: 'formatselect, fontselect, fontsizeselect, styleselect, hr, sub, sup, forecolor, backcolor, forecolorpicker, backcolorpicker, charmap, visualaid, anchor blockquote',
      theme_advanced_buttons3: ''
    });
  });
</script>

forms:

<%= render :partial => 'shared/mce', :locals => {:f => f} %>

I'm only using tinymce on columns named "content". If your columns have differing names, you'll have to adjust your partial locals to suit.

Maybe there's a better way to customize the buttons and layout without modifying the gem, but this is working well enough for me.

分享给朋友:
您可能感兴趣的文章:
随机阅读: