ruby-on-rails-3

Rack ssl not working with Thin

和自甴很熟 提交于 2019-12-30 09:58:46
问题 I installed rack ssl for Rails 3.07 per these instructions: http://www.simonecarletti.com/blog/2011/05/configuring-rails-3-https-ssl/ It is not working. The first https request (for the login page) is made and the page is served securely, but when you login it redirects to a non-secure http URL. I am running Thin server. Does it work for Thin? What about Webrick? Any ideas? Thanks. 回答1: For Thin, you can pass your SSL information in using the following options: $ thin --help SSL options: -

Rails 3 I18n label translation for nested_attributes in has_many relationship

…衆ロ難τιáo~ 提交于 2019-12-30 09:53:27
问题 Using: Rails 3.0.3, Ruby 1.9.2 Here's the relationship: class Person < ActiveRecord::Base has_many :contact_methods accepts_nested_attributes_for :contact_methods end class ContactMethod < ActiveRecord::Base attr_accessible :info belongs_to :person end Now when I try to customize the contact_method labels in I18n, it doesn't recognize it. en: helpers: label: person[contact_methods_attributes]: info: 'Custom label here' I have also tried: person[contact_method_attributes] This works just fine

Routing form submission to a different controller

喜欢而已 提交于 2019-12-30 09:50:49
问题 How do I specify the Controller and Action in a form submission? I am trying to use a 'Clients' Controller to create an Account and an associated Person ('Client'). Here are the pertinent models. A Person belongs either to an Account directly (which I am calling a 'Client') or to a Location and Organization within an Account. class Account < ActiveRecord::Base has_many :organizations has_many :persons, :as => :linkable accepts_nested_attributes_for :organizations end class Person <

Pundit::AuthorizationNotPerformedError

人走茶凉 提交于 2019-12-30 09:18:29
问题 I try install pundit. But when I set up the gem I have this message. error message I don't really understand. I am user.admin maybe is there a conflict? Thank you for your answer. 回答1: Pundit adds a method to your controller called verify_authorized that ensures that the authorize method is called somewhere in your controller action. You likely setup an after_action that calls verify_authorized (https://github.com/elabs/pundit#ensuring-policies-and-scopes-are-used). Make sure you're calling

Pundit::AuthorizationNotPerformedError

依然范特西╮ 提交于 2019-12-30 09:17:10
问题 I try install pundit. But when I set up the gem I have this message. error message I don't really understand. I am user.admin maybe is there a conflict? Thank you for your answer. 回答1: Pundit adds a method to your controller called verify_authorized that ensures that the authorize method is called somewhere in your controller action. You likely setup an after_action that calls verify_authorized (https://github.com/elabs/pundit#ensuring-policies-and-scopes-are-used). Make sure you're calling

Rails conditional validation in model

时间秒杀一切 提交于 2019-12-30 08:14:16
问题 I have a Rails 3.2.18 app where I'm trying to do some conditional validation on a model. In the call model there are two fields :location_id (which is an association to a list of pre-defined locations) and :location_other (which is a text field where someone could type in a string or in this case an address). What I want to be able to do is use validations when creating a call to where either the :location_id or :location_other is validated to be present. I've read through the Rails

Undefined method `instance' for Capistrano::Configuration:Class

我的未来我决定 提交于 2019-12-30 08:07:31
问题 I am trying to get Capistrano up and running for the first time in a rails app. I have a linux server running Ubuntu 12.04, nginx, unicorn and rails, however, I seem to be running into a few issues. I am also using Capistrano 3.0.0, rails 3.2.14, bundler 1.4.0 & ruby 1.9.3p448 using RVM. I only have a production stage set up and at this point in time and I'm only concerned with Capistrano communicating with my server and pushing my code from github ( No migrations and bundling etc just yet).

How can I “extract” values from a multidimensional array in a smart way?

 ̄綄美尐妖づ 提交于 2019-12-30 08:02:17
问题 I am using Ruby on Rails 3.2.2 and Ruby 1.9.2. Given the following multidimensional Array : [["value1", "value1_other"], ["value2", "value2_other"], ["value3", "value3_other"]] I would like to get ( note : I would like to "extract" only the first value of all "nested" Array s): ["value1", "value2", "value3"] How can I make that in a smart way? 回答1: You can use Array#collect to execute a block for each element of the outer array. To get the first element, pass a block that indexes the array.

Parsing XLS Spreadsheet in Rails using Roo Gem

狂风中的少年 提交于 2019-12-30 07:44:13
问题 I am trying to parse a XLS file with the roo gem without using a file upload plugin. Unfortunately I can not access the data of the File. I get the error: #<File:0x007ffac2282250> is not an Excel file So roo is not recognizing the file as an Excel file. Do I need to save the file locally to use roo or is there a way around that. I would like to parse the data of the excel file directly into the database. The params that are coming through: Parameters: {"utf8"=>"✓", "authenticity_token"=>

How to incorporate Rails Engine ApplicationController methods in a main app?

强颜欢笑 提交于 2019-12-30 07:27:08
问题 How do I incorporate a Rails engine ApplicationController (it's methods) into a main app? I need to access these engine controller methods, and I'd like to do it without using an 'Include' in my main app's ApplicationController. module MyEngine class Engine < Rails::Engine initializer "myengine.load_helpers" do ActiveSupport.on_load(:action_controller) do include MyEngine::Helpers end end end end The above was posted on A way to add before_filter from engine to application, but my