2016-06-08 31 views
1

我试图用如何添加iframe到ruby on rails 4.2.6中的sanitized标签?

config.action_view.sanitized_allowed_tags 

我试图找到什么标签都已经使用控制台允许的iframe添加到santized标签。

[email protected]:~/workspace/corse (master) $ heroku run rails c 
Running rails c on ⬢ fa4... up, run.9396 
Loading production environment (Rails 4.2.6) 
irb(main):001:0> puts helper.sanitized_allowed_tags.to_a 
NoMethodError: undefined method `sanitized_allowed_tags' for #<ActionView::Base:0x007f18ea91ea60> 
     from /app/vendor/bundle/ruby/2.3.0/gems/metamagic-3.1.7/lib/metamagic/view_helper.rb:30:in `method_missing' 
     from (irb):1 
     from /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/console.rb:110:in `start' 
     from /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/console.rb:9:in `start' 
     from /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:68:in `console' 
     from /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in `run_command!' 
     from /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands.rb:17:in `<top (required)>' 
     from /app/bin/rails:8:in `require' 
     from /app/bin/rails:8:in `<main>' 
irb(main):002:0> 

任何想法如何添加它而不忽略其他标签?由于

回答

2

请对下面的例子看看:

module Tapp 
    class Application < Rails::Application 
    # In config/application.rb 
    config.action_view.sanitized_allowed_tags = ['strong', 'em', 'a', 'br', 'iframe'] 
    # ... 
end 

我的应用程序称为Tapp,我敢肯定你会在这里有另外一个名字;)

然后在控制台:

[[email protected] ~/workspace/tapp]$ rc 
Loading development environment (Rails 4.2.6) 
[1] pry(main)> Tapp::Application.config.action_view[:sanitized_allowed_tags] 
=> ["strong", "em", "a", "br", "iframe"]