ruby-on-rails-3.2

Rails Update to 3.2.11 breaks running multiple servers

风流意气都作罢 提交于 2019-11-26 20:57:55
问题 Our application runs two Rails servers at different ports that talk to each other. Using Rails 3.2.8, I could open a terminal, cd to the project, run rails s -p3000 , open another terminal, run rails s -p3001 and everything worked fine. The gemfile contains thin , so thin would be launched automatically, but using the rails s would allow using the --debugger when needed. Since updating the Rails 3.2.11 this no longer works. I get an error: "A server is already running. Check /home/george

No secret option provided to Rack::Session::Cookie warning?

你离开我真会死。 提交于 2019-11-26 19:57:29
I am running Rails 3.2.3, Ruby 1.9 under Fedora 17. I get this warning, when I run rails s , and how do I fix? SECURITY WARNING: No secret option provided to Rack::Session::Cookie. This poses a security threat. It is strongly recommended that you provide a secret to prevent exploits that may be possible from crafted cookies. This will not be supported in future versions of Rack, and future versions will even invalidate your existing user cookies. This is a Rails bug, as the subclass is violating the superclass API contract. The warning can be safely ignored by Rails users. ( https://github.com

ERROR: 'rake/rdoctask' is obsolete and no longer supported. Use 'rdoc/task' (available in RDoc 2.4.2+) instead

↘锁芯ラ 提交于 2019-11-26 19:18:40
问题 Seems the last post for this problem was closed for one reason or another so I'll try my luck... I'm trying to run a simple "rake db:migrate" command. When I do, I get the error in the title. Yes, the solution "appears" obvious but it's not because I don't my Rakefile does not contain any references to 'rake/rdoctask'. It seems to be coming from documentation.rake but when I try to change that file as recommended by the error, I get a different error. I have found a couple of posts declaring

categories and sub-categories model rails

核能气质少年 提交于 2019-11-26 19:03:41
问题 Without using any gems how do I do this in rails? Main Category Sub Category Sub Category Sub Category Main Category Sub Category Sub Category Sub Category Main Category Sub Category Sub Category Sub Category I have a table that consists of | id | level1 | level2 | Level 1 being the main category and Level 2 being the subcategory I would like it displayed in the view like above. After looking around on the internet everyone seems to recommend using acts-like-a-tree gem, but i want to avoid

Rails database defaults and model validation for boolean fields

孤街浪徒 提交于 2019-11-26 16:59:56
问题 In a Rails model I have an attribute is_subscriber , when I constructed a db migration to add this column to the database I specified the default value to be false: t.boolean "is_subscriber", :default => false I also specified in the model that this attribute needs to be present: validates :is_subscriber, presence: true So why do I get this error when I create a model instance without specifying this attribute? 2012-05-08T21:05:54+00:00 app[web.1]: ActiveRecord::RecordInvalid (Validation

Using Rails link_to for links that post

纵饮孤独 提交于 2019-11-26 15:39:22
问题 I have a link that I need to submit a post request with. Normally, I'd use jQuery and prevent the link's default behavior and then submit a form to the destination. This seems like something Rails should be able to help me out with. Sure enough, the link_to method has an option for specifying a POST http method: link_to "Profile", 'http://example.com/profile', method: :post That works, but I need to add 2 parameters too. I tried: link_to "Profile", 'http://example.com/profile', method: post,

strong parameters permit all attributes for nested attributes

南笙酒味 提交于 2019-11-26 15:37:50
问题 Is there a way in strong parameters to permit all attributes of a nested_attributes model ? Here is a sample code. class Lever < ActiveRecord::Base has_one :lever_benefit accepts_nested_attributes_for :lever_benefit end class LeverBenefit < ActiveRecord::Base # == Schema Information # id :integer not null, primary key # lever_id :integer # explanation :text end For lever strong parameters i am writing currently this def lever params.require(:lever).permit(:name,:lever_benefit_attributes => [

Using send_file to download a file from Amazon S3?

大憨熊 提交于 2019-11-26 11:55:52
问题 I have a download link in my app from which users should be able to download files which are stored on s3. These files will be publicly accessible on urls which look something like https://s3.amazonaws.com/:bucket_name/:path/:to/:file.png The download link hits an action in my controller: class AttachmentsController < ApplicationController def show @attachment = Attachment.find(params[:id]) send_file(@attachment.file.url, disposition: \'attachment\') end end But I get the following error when

Ruby on Rails Best practices - Big Controller vs Small Controller

那年仲夏 提交于 2019-11-26 11:28:17
问题 I need some informations for the best practices in Ruby on Rails, especially with Controller who have to do a lot of things , so, a simple \"show\" action is now up to lines. I know, it\'s not really good, and I have specific code in it. Here is a sample code: def show sound = Sound.find(params[:id]) @xml_path = File.dirname(sound.file.path) s3 = AWS::S3.new( :access_key_id => \'XXX\', :secret_access_key => \'XXX\') @url = s3.buckets[\'dev\'].objects[sound.file.path[1..-1]].url_for(:read,

Rails Routes based on condition

我怕爱的太早我们不能终老 提交于 2019-11-26 11:10:41
问题 I have three roles: Instuctor, Student, Admin and each have controllers with a \"home\" view. so this works fine, get \"instructor/home\", :to => \"instructor#home\" get \"student/home\", :to => \"student#home\" get \"admin/home\", :to => \"admin#home\" I want to write a vanity url like below which will route based on the role of the user_id to the correct home page. get \"/:user_id/home\", :to => \"instructor#home\" or \"student#home\" or \"admin#home\" How do I accomplish this? 回答1: You can