activerecord

Disable XSS and HTML Sanitization in Rails 3

China☆狼群 提交于 2019-12-13 00:19:24
问题 I'm having an issue where when I have the contents of my rich text editor saved into the database using activerecord the html content is stripped of the html contents (I think it fires html_safe on it). I tried overriding the html_safe method on the content string, but nothing works. content = "<p>hello</p>" @article.content = content puts @article.content # "<p>hello</p>" @article.save puts @article.content # "<>hello</>" How can you override the html stripping capabilities in activerecord

How to use :inverse_of with multiple associations?

冷暖自知 提交于 2019-12-13 00:08:38
问题 Does anyone know what I should put in the empty fields below to make this relationship work out of the box? I am very close to making this work as all associations work flawlessly. The only issue is that I cannot save a user with fruits attached to it as, currently, there is no :inverse_of. I need the :inverse_of pointing in the right direction so that I can save a user with fruits instead of having to save the user first and then attach fruits to it later. Thank you! UPDATED AFTER COMMENTS:

Upgrading to Rails 3.2.8 causes stack level too deep error with ActiveRecord

懵懂的女人 提交于 2019-12-12 22:48:37
问题 I am fairly new to Ruby however I am running into an issue which I am having trouble getting to the bottom of. My simple application was working fine and then, after upgrading the Rails version to 3.2.8 I hit an issue when trying to query my database for records. This works fine when using Rails 3.0.7 but after upgrading to rails 3.2.8 it starts to fail with a Stack Level too deep error. My model looks like this: class Resource < ActiveRecord::Base validates :title, :presence => true, :length

rails 5 enum where “like”

旧街凉风 提交于 2019-12-12 22:43:36
问题 I'm trying to query an activerecord model enum and use the like operator in the where method, and it just doesnt work. Is there some trick to allow me to query an enum this way? Works fine on regular columns. Here it is in the console. Regular string column (title) works as shown below irb(main):092:0> Proposal.select(:id,:department,:status).where('title like "test%"') Proposal Load (0.3ms) SELECT "proposals"."id", "proposals"."department", "proposals"."status" FROM "proposals" WHERE (title

Yii conditional relation

痴心易碎 提交于 2019-12-12 21:39:01
问题 I have a chat table with fields admin TINYINT owner_id INTEGER The goal is to have two relations in Yii: 'admin'=>array( self::BELONGS_TO, 'Admin', 'owner_id', 'condition'=>'admin=1', ), 'user'=>array( self::BELONGS_TO, 'User', 'owner_id', 'condition'=>'admin=0', ), However, I got General error: 1 no such column: admin , and could manage only by adding all_ones and all_zeros columns to Admin table, so I could write 'admin'=>array( self::BELONGS_TO, 'Admin', array('owner_id' => 'id', 'admin' =

Two Tables Serving as one Model in Rails

家住魔仙堡 提交于 2019-12-12 21:18:14
问题 Is is possible in rails to setup on model which is dependant on a join from two tables? This would mean that for the the model record to be found/updated/destroyed there would need to be both records in both database tables linked together in a join. The model would just be all the columns of both tables wrapped together which may then be used for the forms and so on. This way when the model gets created/updated it is just one form variable hash that gets applied to the model? Is this

Accessing parent through unsaved child association (has_many through)

∥☆過路亽.° 提交于 2019-12-12 20:30:20
问题 I have payments with one transaction associated with each payment. The transactions can be associated with payments, deposits, etc. so I need a :through relation. The Payment class: class Payment < ActiveRecord::Base has_many :payment_transactions has_many :transactions, :through => :payment_transactions end And the Transaction class: class Transaction < ActiveRecord::Base has_one :payment_transaction, :inverse_of => :transaction has_one :payment, :through => :payment_transaction end And

ActiveRecord fails to update HABTM relation

家住魔仙堡 提交于 2019-12-12 19:32:12
问题 I'm using a simple model for user authorisation with two ActiveRecords User and Role User and Role have a HABTM relation to each other. I tried to created a user interface for assigning roles to users with simple checkboxes - just like in Railscasts Episode #17. My problem is that neither User#new nor User#update_attributes use the parameters submitted by my form to update the relation between the User object and its roles. params[:user][:role_ids] contains the correct values. But calling

Nested association/join in rails

时光怂恿深爱的人放手 提交于 2019-12-12 19:18:02
问题 I have a seat object that has a car object that has a owner that has a name . I want to display the car brand and the car 's owner 's name together. How do I do this in one query? eg: class Seat < ActiveRecord::Base belongs_to :car def description "I am in a #{car.brand} belonging to #{car.owner.name}" # --> how do I replace this with one query? end end I'll note that this is a highly contrived example to simplify my question. I'm doing this thousands of times in a row, hence the need for

schema.rb index different from individual migration index

拟墨画扇 提交于 2019-12-12 19:09:43
问题 I have this for my migration: class CreateCategories < ActiveRecord::Migration def up create_table :categories do |t| t.integer :parent_id t.string :title, :null => false end execute('CREATE UNIQUE INDEX ix_categories_root_title ON categories (title) WHERE parent_id IS NULL') end def down drop_table :categories end end But when I peeked into db/schema.rb I saw this instead: ActiveRecord::Schema.define(:version => 20110808161830) do create_table "categories", :force => true do |t| t.integer