ruby-on-rails-3.1

Define paperclip style sizes dynamicaly

泄露秘密 提交于 2019-12-11 07:14:36
问题 I have an application where a user chooses a template. On this template the user can upload an image. I use paperclip to upload the images. Each template has different image sizes. Is it possible to set an image style => 'widthxheight' dynamically in paperclip? I want this functionality because if the user decides to change template then they don't have to upload the photo again they just crop the 'original'. Thanks for any help. I will try to clear this up. A user uploads an image for the

Relationships => through with polymorphic_path?

时光总嘲笑我的痴心妄想 提交于 2019-12-11 06:09:27
问题 my models are: class City < ActiveRecord::Base belongs_to :region has_many :activities has_many :restaurants end class Activity < ActiveRecord::Base belongs_to :city end I want acces all activities from all the cities. From a previous question on stackoverflow, i read that i can't do this @cities.activities, instead i did the following: add has_many through association to Region class Region < ActiveRecord::Base has_many :activities, :through => :cities end @activities = @region.activities

Rails: Many-to-many flattening with only the join table

空扰寡人 提交于 2019-12-11 05:56:53
问题 I have a model object which is linked to a list of countries in a many-to-many relationship. The countries are keyed by their ISO 3166 alpha-2 codes. The thing I'd like to accomplish is to save to use of a Country class and table, and only have my object have an accessor in the form of object.countries that will return an array of strings, e.g: ["IL", "US", "IT", ... ] . Essentially, a sort of has_and_belongs_to_many action with only the join table. Is this possible? Is there a best practice

undefined method `model_name'

三世轮回 提交于 2019-12-11 05:45:54
问题 i am getting this undefined method for albums controller and model any solutions?... undefined method `model_name' for ActiveRecord::Relation:Class Extracted source (around line #6): 3: >> 4: new album 5: 6: = form_for @albums do |f| 7: = f.error_messages 8: %p 9: = f.label :name =link_to 'albums', albums_path >> new album = form_for @album do |f| = f.error_messages %p = f.label :name = f.text_field :name %p = f.label :description = f.text_field :description, :rows => 3 %p = f.submit %p= link

Trouble on deploying with Bundler and Capistrano

放肆的年华 提交于 2019-12-11 05:28:52
问题 I am using Ruby on Rails 3.1.0 and the Capistrano gem. As wrote in the Bundler official documentation in the "Automatic deployment with Capistrano" section, I added the require 'bundler/capistrano' to the top of my deploy.rb file. Now, when I run the cap deploy:migrations command (Deploy and run pending migrations) I get the following error: ... * executing "cd /<my_application_path>/releases/20111026132212 && bundle install --gemfile /<my_application_path>/releases/20111026132212/Gemfile -

Not able to run/install Gems using Gemfile

心不动则不痛 提交于 2019-12-11 05:28:52
问题 When i give bundle install or bundle exec i am getting this error Could not find gem 'acts_as_ferret-0.4.4.gem (>= 0) ruby' in any of the gem sources listed in your Gemfile. Apparently the first gem in the Gemfile is acts_as_ferret-0.4.4 and source is source 'http://rubygems.org' I tried other sources also but still not working!!! 回答1: As Pete is saying there probably is a problem with your gemfile Try to open it and see if your acts_as_ferret looks something like this. gem "acts_as_ferret",

Testing backbone views with jasmine

允我心安 提交于 2019-12-11 05:21:40
问题 I am trying to test my backbone views with jasmine. I use underscore library to generate templates for the backbone views. For testing purposes I use jasmine jasmine-jquery I am unable to load the fixtures in the jasmine tests as the views have embeded ruby. Here is my code Backbone view AlbumView = Backbone.View.extend({ template: _.template($('#album-template').html()), render: function() { $('#albums').append(this.template(this.model.attributes)); } }); This view uses the following

Trouble on eager loading and using the 'where' method

旧街凉风 提交于 2019-12-11 04:54:14
问题 I am running Ruby on Rails 3.1. I am using the includes method and I would like to understand why when I call the where method on an eager loaded collection it reloads associated objects instead of just finding that object in the eager loaded collection. Since all related objects are already been eager loaded I expect that the where method does not hit the database to reload those objects! That is, I have the following: article_categories = article .categories .where(:user_id => @current_user

Heroku run rake db:migrate error with “no such file to load — bundler/setup”

北战南征 提交于 2019-12-11 04:52:35
问题 I'm trying to do a "heroku run rake db:migrate", and get this error: es-MacBook-Pro:project e$ heroku run rake db:migrate Running rake db:migrate attached to terminal... up, run.1 (in /app) rake aborted! no such file to load -- bundler/setup <internal:lib/rubygems/custom_require>:29:in `require' <internal:lib/rubygems/custom_require>:29:in `require' /app/config/boot.rb:6:in `<top (required)>' <internal:lib/rubygems/custom_require>:29:in `require' <internal:lib/rubygems/custom_require>:29:in

Devise routing error: No route matches [GET] “/users/sign_out”

拟墨画扇 提交于 2019-12-11 04:39:24
问题 routes.rb => devise_for :users resources :posts match "posts/:id/categ" => "posts#categ" match "posts/:id/tag_posts" => "posts#tag_posts" match "posts/searcharchive" => "posts#searcharchive" #post "posts/searcharchive" resources :categories resources :comments resources :countpages rake routes => new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"} user_session POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"} destroy