ruby-on-rails-4

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?

using an associated field name in slug_candidates in friendly_id

烂漫一生 提交于 2020-01-15 03:09:08
问题 Is it possible to use a association in my slug_candidates method? for example, where my model belongs_to :car def slug_candidates [ [car.owner, :horsepower, "horsepower"], [car.owner, car.nickname, :horsepower, "horsepower"] ] end right now it returns NoMethodError: undefined method `owner' for nil:NilClass 回答1: I assume this is a method defined in an ActiveRecord model. It's because one of the records you are using does not have a car (ie. it is nil ). So when you do car.owner on that

Trouble upgrading Ruby on Rails from version 3.2.13 to 4.0.0

跟風遠走 提交于 2020-01-14 18:50:46
问题 For a my application I am trying to upgrade Ruby on Rails from version 3.2.13 to 4.0.0 and I am in trouble when installing / updating some gem (by using the Bundler), specifically the globalize3 gem. I am running Ruby 2.0.0-p247 . Given my Gemfile is: gem 'rails', '4.0.0' gem 'globalize3', github: 'svenfuchs/globalize3', branch: 'rails4' gem 'delayed_job', :git => 'git://github.com/collectiveidea/delayed_job.git', :branch => 'master' gem 'delayed_job_active_record', :git => 'git://github.com

Trouble upgrading Ruby on Rails from version 3.2.13 to 4.0.0

落爺英雄遲暮 提交于 2020-01-14 18:49:34
问题 For a my application I am trying to upgrade Ruby on Rails from version 3.2.13 to 4.0.0 and I am in trouble when installing / updating some gem (by using the Bundler), specifically the globalize3 gem. I am running Ruby 2.0.0-p247 . Given my Gemfile is: gem 'rails', '4.0.0' gem 'globalize3', github: 'svenfuchs/globalize3', branch: 'rails4' gem 'delayed_job', :git => 'git://github.com/collectiveidea/delayed_job.git', :branch => 'master' gem 'delayed_job_active_record', :git => 'git://github.com

How can I prevent duplicate wrappers on a jQuery DataTable when navigating back in the presence of Turbolinks?

烂漫一生 提交于 2020-01-14 14:51:44
问题 I'm using jQuery DataTables in a new Rails 4.2 project. I've got a large number of results that need to be filtered on group, project, and status. Choosing the group filters the project selection, via a roundtrip through the application, and the project selection filters the table the same way. I save the group & project in session variables so that, when the user changes pages, then clicks the main link to come back, it will remember their selection, and get them back to where they were.

How can I prevent duplicate wrappers on a jQuery DataTable when navigating back in the presence of Turbolinks?

谁都会走 提交于 2020-01-14 14:51:09
问题 I'm using jQuery DataTables in a new Rails 4.2 project. I've got a large number of results that need to be filtered on group, project, and status. Choosing the group filters the project selection, via a roundtrip through the application, and the project selection filters the table the same way. I save the group & project in session variables so that, when the user changes pages, then clicks the main link to come back, it will remember their selection, and get them back to where they were.

Loop variable grouping by date

丶灬走出姿态 提交于 2020-01-14 14:23:45
问题 I have some sporting results that i'd like to loop through and group under dates in a table. For example; |Sat, 20| |Game 1 Results| |Game 2 Results| |Sun, 21| |Game 3 Results| |Sat, 27| |Game 4 Results| My Controller @matches = Match.group([:matchId, 'DATE(matchDate)']).inject([]) do |results, matches| team_names = Match.where(matchId: matches.matchId) results << [matches.id, matches.matchDate, team_names.first.team.name, team_names.last.team.name, team_names.first.points, team_names.last

ActiveAdmin Form not saving nested object

╄→尐↘猪︶ㄣ 提交于 2020-01-14 12:38:19
问题 Using ActiveAdmin with Rails 4, I have two models, Document and Attachment with a one-to-many relationship between them. # models/document.rb class Document < ActiveRecord::Base has_many :attachments accepts_nested_attributes_for :attachments end # models/attachment.rb class Attachment < ActiveRecord::Base belongs_to :document end I registered the models and included permit_params for all the fields in each. Now I used has_many in the form view in the below code. This shows an option to add

ActiveAdmin Form not saving nested object

[亡魂溺海] 提交于 2020-01-14 12:37:08
问题 Using ActiveAdmin with Rails 4, I have two models, Document and Attachment with a one-to-many relationship between them. # models/document.rb class Document < ActiveRecord::Base has_many :attachments accepts_nested_attributes_for :attachments end # models/attachment.rb class Attachment < ActiveRecord::Base belongs_to :document end I registered the models and included permit_params for all the fields in each. Now I used has_many in the form view in the below code. This shows an option to add

how to access multiple databases in single rails application in rails 4?

与世无争的帅哥 提交于 2020-01-14 10:23:16
问题 I am new to rails, don't know how to access multiple databases in rails single application. I will try like this config/database.yml default: &default adapter: mysql2 encoding: utf8 pool: 5 username: root password: root socket: /var/run/mysqld/mysqld.sock reconnect: true development: <<: *default database: connection_development <<: *default database: connection_test second database log_database_production: adapter: mysql2 encoding: utf8 pool: 5 host: 192.168.100.97 port: 3306 #ip address of