ruby-on-rails-3

Carrierwave Cropping

余生颓废 提交于 2020-01-12 10:01:55
问题 I have an CarrierWave ImageUploader which creates a couple of versions of an original image that need to be cropped based on values in my model (crop_x, crop_y, crop_w, and crop_h). class ImageUploader < CarrierWave::Uploader::Base include CarrierWave::MiniMagick ... version :t do process :cropper process :resize_to_fill => [75, 75] end ... def cropper manipulate! do |img| img = img.crop "#{model.crop_x}x#{model.crop_y}+#{model.crop_w}+#{model.crop_h}" img end end end The problem that I'm

How do I get my new registrations Devise form to be AJAXified?

删除回忆录丶 提交于 2020-01-12 09:54:15
问题 What I want to happen is when the account is successfully created, the form that was submitted should disappear and a message should appear (depending on the status of the registration). If it was successful, they should see a simple "Thank you. Please check your email." If it wasn't, then they should see an appropriate message - like "Sorry, that email has already been taken." This is my form: <div class="nine columns offset-by-three sign-up-form"> <%= form_for(resource, :as => resource_name

Angularjs ngResource '@id'

会有一股神秘感。 提交于 2020-01-12 08:44:31
问题 I have a quick question. In angular js where (like which object) does the '@id' come from in the following piece of code from a rails app? var User = $resource("/users/:id", {id: '@id'}); I know it sets the default id. Thanks 回答1: From the AngularJs documentation: "If the parameter value is prefixed with @ then the value of that parameter is extracted from the data object (useful for non-GET operations)." This means that when calling a non-GET operation, like POST, you can pass the id as one

How do you run Rails with HTTPs locally for testing?

青春壹個敷衍的年華 提交于 2020-01-12 08:12:29
问题 Our dev envs use HTTP, prod uses HTTPS, this is causing issues that we can't reproduce locally with are HTTPS related. How can I run rails with SSL locally for testing purposes? Is there a Webrick config? Thanks 回答1: you should to use thin to do it: $ sudo apt-get install thin And add this line in config/application.rb config.force_ssl = true Then run app on thin with command line: $ thin start --ssl 回答2: I think the question here is specific to the Rails 'testing' environment, which might

Permission Error When Trying To Install Rails (OSX)

我的未来我决定 提交于 2020-01-12 07:49:07
问题 I am new to programming and am trying to get rails installed on my terminal. I have been following instructions from a friend, installing the xcode command line tools, homebrew, git, rbenv, ruby-build, ruby gems, ruby, and postgres. But whenever, I try $gem install rails, I get the following: Russell-Silvers-MacBook-Pro:~ Russell_Silver$ gem install rails ERROR: While executing gem ... (Errno::EACCES) Permission denied @ rb_sysopen - /Users/Russell_Silver/.rbenv/versions/2.1.5/lib/ruby/gems/2

Sunspot / Solr / Rails: Model Associations are not updating in the Index

眉间皱痕 提交于 2020-01-12 05:43:26
问题 I have a Fieldnote model in my app, which has_many :activities attached to it through a table called :fieldnote_activities. I then define a searchable index this way: searchable :auto_index => true, :auto_remove => true do integer :id integer :user_id, :references => User integer :activity_ids, :multiple => true do activities.map(&:id) end text :observations end And then I have a Search model to store / update searches. The search model thus also has its own associations with activities. I

Unwanted form parameters being appended to pagination links

落爺英雄遲暮 提交于 2020-01-12 04:39:24
问题 I have a page which is used for searching through listings by submitting data using the supplied forms. The form parameters are submitted via ajax (post request), a new record is created in the searches table and then the listings are displayed (dynamically, on the same page the form is submitted from) via the show action for this record. The results have pagination links provided by kaminari like so: <%= paginate matches, :params => {:controller => 'searches', # I have to specify the id

ActiveRecord Association select counts for included records

放肆的年华 提交于 2020-01-12 04:38:08
问题 Example class User has_many :tickets end I want to create association which contains logic of count tickets of user and use it in includes (user has_one ticket_count) Users.includes(:tickets_count) I tried has_one :tickets_count, :select => "COUNT(*) as tickets_count,tickets.user_id " ,:class_name => 'Ticket', :group => "tickets.user_id", :readonly => true User.includes(:tickets_count) ArgumentError: Unknown key: group In this case association query in include should use count with group by .

Ruby - Difference between :variable and @variable

孤街醉人 提交于 2020-01-12 03:39:12
问题 As a Ruby on Rails newbie, I understand that the "@" and ":" references have different meanings. I saw this post in SO, which described some of the differences. @ indicates a instance variable (e.g., @my_selection) : indicates an alias (e.g., :my_selection) I ran into a situation where I had a standard MVC page, similar to all of the other forms/pages in my webapp. html.erb snippet <%= form_for @my_selection do |f| %> route.rb snippet resources :my_selections When I attempt to access this

Setting default search parameter on Ransack for rails

浪子不回头ぞ 提交于 2020-01-12 03:25:05
问题 I've been wracking my brain over this but can't get it. I feel like the answer is probably obvious. What I'm trying to do is the following: I have an index controller which lists a series of Jobs which I can search using Ransack. Each job has a completion date which either has a date in it or is null (unfinished). Currently, the search itself works great. I would like to make it so that the index page loads up showing only the unfinished work, but I also want it to work so that when someone