ruby-on-rails-3.1

Delayed_job (2.1.4) error: Job failed to load: instance of IO needed. Handler nil

不想你离开。 提交于 2019-12-09 23:59:37
问题 I created a simplistic achievements system and wanted to introduce delayed_job (2.1.4) to take care of the processing. However, the handler column in the delayed_jobs table is always nil, which results in the last_error text: Job failed to load: instance of IO needed. Handler nil Here is my setup: Achievement Observer class AchievementObserver < ActiveRecord::Observer observe User, Comment, ... def after_create(record) # initiate delayed job to check conditions Delayed::Job.enqueue(TrophyJob

Adding button click counter in rails 3

泪湿孤枕 提交于 2019-12-09 20:54:30
问题 I want to add buttons on my article so that I can know the number of times its clicked and update counter on the database, I am using mongoid ,my model is: class Article include Mongoid::Document include Mongoid::Timestamps field :title, :type => String field :content, :type => String field :likes, :type => Integer ,:default => 0 field :dislikes, :type =>Integer, :default => 0 field :spam, :type => Integer, :default => 0 end My articles show controller is: def show @article = Article.find

Rails 3.1 asset urls in SCSS files do not seem to be referencing the assets correctly

好久不见. 提交于 2019-12-09 19:40:39
问题 I just upgraded from Rails 3.0 to Rails 3.1. I have a foo.css.scss file that references an image ( /app/assets/images/foo.png ) as follows: .foo { background-image: image-url('foo.png'); } The problem is that my foo.png file is not loaded and I see 404 errors in my logs. The actual css entry that is generated is: background-image: url(/images/foo.png); which is wrong (?) because the image can be found at /assets/foo.png and not at /images/foo.png . Note that I am still working on development

Elastic Search/Tire: How to map to association attribute?

南笙酒味 提交于 2019-12-09 18:40:53
问题 I'm using Tire for Elastic Search. In my application I have 2 models; Price and Product. I'm trying to search my Price class and use the Product it belongs to's :name attribute for the search field. Right now if I had a product called Product 1 and type in "pro", "prod" or "duct", no results come up. But typing "product" or "Product" shows the results. I believe the problem lies in my mapping. I looked at the query and its: ...localhost:3000/search/results?utf8=%E2%9C%93&query=product When I

How do i include Rails join table field in the form?

我与影子孤独终老i 提交于 2019-12-09 18:29:31
问题 In this scenario I can insert values to the Member table and the Club table. But there is a field called :task in the memberships table that I want to submit a value to, and in the Memberships table member_id and club_id are inserted automatically by Rails. How do I include the task field in the form below? Thank you in advance. View/form: <%= form_for @member ,:url=>{:action =>"create"} do |f| %> <%= f.text_field :email %> <%= f.fields_for :clubs do |s| %> <%= s.text_field :name %> <% end %>

ActiveAdmin — How to access instance variables from partials?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-09 15:55:08
问题 I can't seem to access instance objects in partials. Example: In controller I have: ActiveAdmin.register Store do sidebar "Aliases", :only => :edit do @aliases = Alias.where("store_id = ?", params[:id]) render :partial => "store_aliases" end end Then in the _store_aliases.html.erb partial I have: <% @aliases.each do |alias| %> <li><%= alias.name %></li> <% end %> This doesn't work. The only thing that does work (which is horrible to do as I'm putting logic in a view is this: <% @aliases =

rails 3.1 assets are not available

旧街凉风 提交于 2019-12-09 14:10:28
问题 I started playing around with rails 3.1.rc4 but the first problem I'm having is that the assets are not available. I created a brand new project and in the index page the rails image gives 404. Actually any assets are available. I checked # application.rb # Enable the asset pipeline config.assets.enabled = true And I tried config.assets.paths << "#{Rails.root}/app/assets/images" and also from the shell $ rake rails:update $ rake assets:clean $ rake assets:precompile had no luck, so I

error precompiling assets when moving to production

▼魔方 西西 提交于 2019-12-09 14:03:50
问题 I am trying to move my project to production, trying to RAILS_ENV=production bundle exec rake assets:precompile gives me an error, without specifying in which file it is. rake aborted! Sass::SyntaxError: Invalid CSS after "}": expected selector or at-rule, was "}" (sass):89 /Users/mac/.rvm/gems/ruby-2.2.3/gems/sass-3.4.23/lib/sass/scss/parser.rb:1207:in `expected' /Users/mac/.rvm/gems/ruby-2.2.3/gems/sass-3.4.23/lib/sass/scss/parser.rb:1137:in `expected' /Users/mac/.rvm/gems/ruby-2.2.3/gems

ArgumentError: You need to supply at least one validation with :if

不问归期 提交于 2019-12-09 14:00:33
问题 I have a simple model class Task < ActiveRecord::Base validates :deadline, :if => :deadline_in_future? def deadline_in_future? Date.today < self.deadline end end All seems ok, but when I in my rails console irb(main):001:0> Task.new ArgumentError: You need to supply at least one validation Where is the problem? 回答1: You forgot to tell validates how you want to validate :deadline . I think you're misunderstanding what :if does; the :if => :deadline_in_future? option means: Validate :deadline

What could happen if I use :without_protection=>true when creating a new model in rails 3.1?

北城余情 提交于 2019-12-09 13:11:18
问题 I have encountered a problem in my application and realized that I could fix it by setting :without_protection => true when creating a model, e.g.: Model.new(params[:model], :without_protection => true). What exactly is rails protecting the models from? Thanks! 回答1: It's protection against unintended mass assignment. The problem with the code you shown is that users can alter the form and change attributes you don't want them to change, like hashed passwords on users or a published status on