ruby-on-rails-3.2

Can Can selectively cache abilities

限于喜欢 提交于 2019-12-11 20:22:38
问题 I know about caching the whole current_ability . Something like def current_ability cached_ability = Rails.cache.read("#{current_user.cache_key}::ability") if cached_ability.present? ability = Marshal.load( cached_ability ) else ability = super Rails.cache.write("#{current_user.cache_key}::ability", Marshal.dump( ability )) end @current_ability = ability end But is there is a way to cache a single ability ? for example I do this : Rails.cache.fetch("#{user.cache_key}::comments::ability") do

undefined method `scoped' for Forum:Module

谁说我不能喝 提交于 2019-12-11 19:15:33
问题 I have been working on a simple forum based on forum monster demo. I am currently trying to update the application from rails 3.0.9 to 3.2.11. When I load the application I get a undefined method `scoped' for Forum:Module Extracted source (around line #13): 10: <%= link_to "Delete Category", category_path(category), :confirm => "Are you sure you want to delete this category?", :method => :delete if can? :manage, category %> 11: </span> 12: </div> 13: <% if category.forums.size > 0 %> 14: <div

File upload won't work in Ruby on Rails 3 using Multipart Form

巧了我就是萌 提交于 2019-12-11 19:14:20
问题 I have a very simple configuration for uploading files. I simply want to upload an image to a database (I know, I know...) with a description. That's it. Here is what my model looks like (which I learned from here). Basically, it is exactly the way the example is setup, only with the attr_protected line to work Rails 3.2: Photo < ActiveRecord::Base # note: there is also a :description attribute!! attr_protected :file_name, :content_type, :binary_data def image_file=(input_data) self.file_name

Cannot map Employee back to User ID correctly

隐身守侯 提交于 2019-12-11 18:37:05
问题 My problem is: I have a User model , Employee , Student , Parent . I don't know how to map each of Employee , Student , Parent back to User ID correctly. because in the current state for example I have differentiating by a normal user and an employee (since the employee is a user as well ) , How can I do so ? For example I will paste Employee and User and Ticket so you can help me to map it correctly because in my system Ticket model is not dealing with the Employee as a User . please I am

Serving static_assets with nginx instead of rails in rails 3.2 [closed]

半城伤御伤魂 提交于 2019-12-11 18:26:53
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I recently deployed a site based on the SpreeCommerce platform. I'm using nginx and would like nginx to serve my static assets. The problem I am having is that when a user uploads new photos for a product on the website the images appear to save correctly (the files are located on the server) but they do not get

Rails 3 has_and_belongs_to_many association: how to assign related objects without saving them to the database

你说的曾经没有我的故事 提交于 2019-12-11 18:08:07
问题 Working with an has_and_belongs_to_many_association class Category has_and_belongs_to_many :projects end I would would like to use a before_filter to set projects before saving categories before_filter :set_projects, :only => [:create, :update] def set_projects @category.assign_attributes({projects: Project.all}) end This works well, except when the category cannot be saved and there is a rollback. The projects are still updated in database. Why this line @category.assign_attributes({projects

How to Upgrade Rails to 4.2?

风格不统一 提交于 2019-12-11 15:24:00
问题 I Want to upgrade my Rails application properly from 3.2.12 to 4.2 ... someone send me this link: http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html at the moment I'm trying to upgrade from 3.2.12 to 4.0 ... i'm hanging on step 5.4: Rails 4.0 no longer supports loading plugins from vendor/plugins. You must replace any plugins by extracting them to gems and adding them to your Gemfile. If you choose not to make them gems, you can move them into, say, lib/my_plugin/* and add an

RAILS: fill Object from Array

寵の児 提交于 2019-12-11 15:07:45
问题 Array is filled from query using arbitrary SQL statement @myarray = myObject.find_by_sql(sql) SQL is designed in such way that each myarray item has same fields as myObject Model, e.g. \#{myObject value: 100, day: 2013-06-15} Ideally, I would like to have array of myObjects Filled with data from Array; Accessible for html; Not saved to the database. Is it at all possible? 回答1: From docs for ActiveRecord::Querying#find_by_sql : Executes a custom SQL query against your database and returns all

Override Rails date_select form helper

南笙酒味 提交于 2019-12-11 15:06:59
问题 I would like to override the date_select form helper in my app (running Rails 3.2), to bring in the :selected parameter from the Rails 4 date_select. Overriding default Rails date_select is a little old now, but I was referencing this to try to make it work. So I have the following in a file in lib/ , included at the bottom of environment.rb : ActionView::Helpers::Tags::DateSelect.class_eval do # # Note: Using ActionView::Helpers::DateTimeSelector as suggested in # linked question doesn't

After upgrading to rails 3.2 I see ActiveRecord::Fixture::FormatError: a YAML error occurred parsing

╄→尐↘猪︶ㄣ 提交于 2019-12-11 15:04:33
问题 I see the following error after upgrading to rails 3.2.12 with ruby 1.9.2. ActiveRecord::Fixture::FormatError: a YAML error occurred parsing /SampelRails/user_properties.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at http://www.yaml.org/faq.html The exact error was: Psych::SyntaxError: couldn't parse YAML at line 1 column 0 I have doubled checked the yml files and they seem to be indented properly. according to https://github