actionviewhelper

How can I allow <source> tags through rails 4 sanitize?

自闭症网瘾萝莉.ら 提交于 2020-01-15 03:41:07
问题 I've been using the sanitize method in a Rails 4 app to scrub a page which displays html that users generate to prevent unsafe things like script injection. So I have a view that looks like: sanitize @user_input Right now I'm having issues when uses are entering video tags with a source tag under it like so: <video><source src="foo.bar"></video> Unfortunately it looks like sanitize is stripping out the source tag so videos are no longer working. How do I use sanitize so it allows source tags?

Issues with rails4 and mongoid on production mode

ε祈祈猫儿з 提交于 2020-01-04 16:58:54
问题 I am working with rails 4.2.x and Mongoid . I am getting the following error when I try to run server in production mode ,but it runs smoothly on development mode, not sure why I am getting this error . I tried precomipling asses but no luck. => Booting Thin => Rails 4.2.1 application starting in production on http://localhost:3000 => Run `rails server -h` for more startup options => Ctrl-C to shutdown server Exiting /home/ratnakar/.rvm/gems/ruby-2.1.5@glimpse/gems/actionview-4.2.1/lib/action

Rails: Preselect a value in ActionView-Helper 'collection_select'

可紊 提交于 2020-01-03 11:31:11
问题 I'm trying to get the ActionView-Helper collection_select to take a value that will be preselected in the dropdown-menu. Neither ( :selected in the html-option-hash) <%= collection_select(:my_object, :my_method, @my_collection, :id, :description_string, {}, {:selected => @my_collection_object.id}) %> nor ( :selected in the option-hash) <%= collection_select(:my_object, :my_method, @my_collection, :id, :description_string, {:selected => @my_collection_object.id}, {}) %> seem to work. What am I

How do I use an ActionView::Helper in a Ruby script, outside of Rails?

大憨熊 提交于 2019-12-20 09:49:30
问题 I am looking to use ActionView::Helpers::NumberHelper from a Ruby script. What all do I need to require etc.? 回答1: ~> irb ruby-1.9.2-p180 :001 > require 'action_view' => true ruby-1.9.2-p180 :002 > ActionView::Base.new.number_to_currency 43 => "$43.00" 回答2: As of Rails 3.2.13, you can do the following: class MyClass include ActionView::Helpers::NumberHelper def my_method ... number_with_precision(number, precision: 2) ... end end You might need to require 'action_view' too. Edit: This answer

How to render images in rails3 select

邮差的信 提交于 2019-12-20 01:42:21
问题 I want to render dropdown list in form with images as options. How to achieve this in rails3? 回答1: I like the msdropdown. You can add the path for the image in the title tag: <select> <option value="1" title="#path for the image">first</option> <option value="2" title="#path for the image">second</option> ... </select> In Rails, you can add the title doing something like: <%= f.select(:yourcolumn, Model.all.map{|p| [p.name, p.id, :title => p.image_url(:thumb)]} I have faced a similar problem

Rails form_tag form writing - with non-active record model

♀尐吖头ヾ 提交于 2019-12-08 16:29:35
问题 I'm somewhat of a Rails newbie. I'm writing a couchrest-rails app, so am not using activerecord for this model. I just figured out that that means that form_for(@model) won't work. I'm trying to work out how to use form_tag -- but most of the examples don't involve new & create actions. This is wrong: <h1>New article</h1> <% form_tag new_article_url(@article), :method => :post do |f| %> <%= f.error_messages %> <p> <%= f.label :title %><br /> <%= f.text_field :title %> </p> <p> <%= f.submit

RoR: undefined method `url_for' for nil:NilClass

北城以北 提交于 2019-12-08 08:24:54
问题 I have a standard Rails application. When a Tip is created, I would like to create a Message for each User who is interested in that Tip. This sounds simple right? It should be... So, we start with a Tip Observer: class TipObserver < ActiveRecord::Observer def after_save(tip) # after the tip is saved, we'll create some messages to inform the users users = User.interested_in(tip) # get the relevant users users.each do |u| m = Message.new m.recipient = u link_to_tip = tip_path(tip) m.body =

Rails console - use image_tag method

*爱你&永不变心* 提交于 2019-12-04 10:49:49
问题 How can I execute a image_tag method in a Rails console Run the console $ rails c Load helpers include ActionView::Helpers Execute the command image_tag('test.png') I got a strange error. Please help! 回答1: Not sure why you're getting that error. It is strange. But the Rails Console exposes the helper methods through the helper variable. So this should work: helper.image_tag('test.png') 回答2: OK... I found the solution. The error is showing only in Rails 3 but I fixed it by setting the config

Rails console - use image_tag method

心已入冬 提交于 2019-12-03 06:07:29
How can I execute a image_tag method in a Rails console Run the console $ rails c Load helpers include ActionView::Helpers Execute the command image_tag('test.png') I got a strange error. Please help! Not sure why you're getting that error. It is strange. But the Rails Console exposes the helper methods through the helper variable. So this should work: helper.image_tag('test.png') OK... I found the solution. The error is showing only in Rails 3 but I fixed it by setting the config.action_controller.asset_host = "http://..." config.action_mailer.asset_host = "http://..." in my environemnt file

How to render images in rails3 select

≯℡__Kan透↙ 提交于 2019-12-01 20:58:56
I want to render dropdown list in form with images as options. How to achieve this in rails3? gabrielhilal I like the msdropdown . You can add the path for the image in the title tag: <select> <option value="1" title="#path for the image">first</option> <option value="2" title="#path for the image">second</option> ... </select> In Rails, you can add the title doing something like: <%= f.select(:yourcolumn, Model.all.map{|p| [p.name, p.id, :title => p.image_url(:thumb)]} I have faced a similar problem some time ago: generate HTML <select> with title inside each <option> to apply the msDropDown