Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

How to add custom menu opton in Tinymce in Rails

Rather than using the default initiator from the gem you could initiate tinymce manually and create the menu item at the same time:

Something like this:

<script type="text/javascript">
        selector: '.my-class textarea',
        toolbar: "styleselect | bold italic |
        setup: function(editor) {
        <% @my_items.each_with_index do |name,
index| %>
            editor.addMenuItem('<%= name
%>', {
                text: '<%= name %>',
                context: 'tools',
                onclick: function() {
name %>');
            <%= index == (@my_items.count - 1)
? '});' : '}),' %>
        < % end %>   

We use a ternary operator to choose the correct closing tag based on the index of the names.

Theoretically you can also do this in the config/tinymce.yml file, but due to the dynamic nature it's not really plausible.

Something else you may want to look into is passing the menu to the activeEditor like:


Categories : Ruby On Rails

Related to : How to add custom menu opton in Tinymce in Rails
add custom validation method in Ruby on Rails
You don't need custom validation to do this, you can use regex to validate the format of password. Add this to your model validates :password, format: { with: /^(?=.*[A-Z]).+$/, allow_blank: true } In Rails, you can do this by using format validator, I have added allow_blank: true to make sure when the field is empty it only throws Can't be blank error message and not format validator error mes

Categories : Ruby On Rails
How to add custom name input field in rails simple_form_for
You need something like attr_accessor in Ruby,What is attr_accessor in Ruby? Please include following in your model,which will make to get values from form to controller. attr_accessor :category

Categories : Ruby On Rails
In Rails 4 How to Test Devise Custom Registration Paths?
You are probably testing the wrong controller. Check your routes (rake routes) to see which controller is assigned to handle your Devise authentication routes. By default I believe it is Devise::SessionsController. I do not think this is your intent, but it is worth mentioning that you should not test the devise gem. Note that requests for ActionController::TestCase are simulated. If you want to

Categories : Ruby On Rails
Rails custom validation error messages on attributes of another model
ActiveModel looks up validation errors in several scopes. Foo and Bar can share the same error message for mode_mismatch if you include it at activerecord.errors.messages instead of activerecord.errors.models: en: activerecord: errors: messages: mode_mismatch: "Foo %{link} has the wrong mode." Using that locale string with the link interpolation then becomes a matter of def

Categories : Ruby On Rails
Rails + simple_form + remote_true + custom controller: how to handle different form actions for 'new' and 'edit'?
I finally chose to add a line before the form: <% url = @task.new_record? ? "/demo/create_task" : "/demo/update_task?id=#{}" %> <%= simple_form_for @task, remote: true, url: url do |f| %> <%= f.input :description %> <%= f.input :deadline %> <%= f.button :submit %> <% end %>

Categories : Javascript
Recently Add
Groups and Users has many oder has many through?
Rails format specifier differences
Capistrano can not create symlinks: file exist
Admin can't delete users. Ruby on Rails 3 - Michael Hartl
Don't show user name who create post
Using Wicked with Devise (2 step signup process)
RubyOnRails Rake test failures
Rails session start event handler
Why ActiveModel::ForbiddenAttributesError error?
How can i track the issue in production RAILS
Cannot install spree gem - ERROR: invalid gem: package is corrupt
Why are the nested resources for Devise authentication not working?
Rails Devise - how to open access to the site root
Rails: respond_with the same template for two methods
rails with postgresl database "role postgres does not exist"
Instance variable in Rails helper not set
Monkey patch rails 3.2 rake task
Rails_admin: Should I have admin_user or user with admin role to manage users and admin panel
undefined method `attachments' for nil:NilClass
Memory usage increase with Ruby 2.1 versus Ruby 2.0 or 1.9
Can a Rails app be deployed without using Heroku Toolbelt? If so, how?
Enable random access to collection with MongoDB
libmysqlclient-dev installation fails
undefined method `name' for nil:NilClass. Can't find but @followed is set
Allowing an arbitrary domain and subdomain in session_store.rb
Pushmeup Gem - Can't send push notifications in Active Admin model
Rails console does not start
GitHub Import: Could not locate Gemfile
AWS::S3::PermanentRedirect in SongsController#index "The bucket you are attempting to access must be addressed using the specified endpoint"
automatically create ActiveRecord parent for association
© Copyright 2017 Publishing Limited. All rights reserved.