ruby-on-rails-3.1

Devise - login from two model

一曲冷凌霜 提交于 2019-12-03 17:22:11
I have two user models, first is from remote database as legacy and for internal company purposes. (Employee logins). Second is our project for public registration and sign in but I want one login form. I have searching long time, but some solutions are confusing for me. First legacy looks like (only for reading and authentication): class CrmUser < ActiveRecord::Base require Rails.root.join('lib', 'devise', 'encryptors', 'sha1') # Include default devise modules. Others available are: # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable, :rememberable, and :omniauthable

How do I replicate class_inheritable_accessor's behavior in Rails 3.1?

旧街凉风 提交于 2019-12-03 17:13:31
问题 Beginning with Rails 3.1, class_inheritable_accessor produces deprecation warnings, telling me to use class_attribute instead. But class_attribute behaves differently in an important way which I will demonstrate. A typical use of class_inheritable_attribute would be a presenter class, like so: module Presenter class Base class_inheritable_accessor :presented self.presented = {} def self.presents(*types) types_and_classes = types.extract_options! types.each {|t| types_and_classes[t] = t.to_s

Generate Thumbnail From pdf in rails paperclip

跟風遠走 提交于 2019-12-03 16:46:07
问题 How can I generate the first page of a pdf as a thumbnail in paperclip? I tried a lot but it's not working has_attached_file :book_url, :styles => { :thumb => "100x100#", :small => "150x150>", :medium => "200x200" } This is giving the name of the pdf as a link but it's not giving the first page of the pdf <%= link_to 'My PDF', @book.book_url.url %> 回答1: Tadas' answer is right, but for those who need more context, you can do something like this: The model below only creates thumbnails for

Where to put private documents to use in Rails applications?

血红的双手。 提交于 2019-12-03 16:09:54
I have some template files I would like to use in my rails App. I was wondering where(under which directory) to put them given two scenarios: They are private to my application (Only webmaster can delete, change them) They are private to my application but also they can be managed by admins(deleted, modified) KobeJohn Update after comments Since you want to serve the files locally, just put them outside of the /public/ folder and outside of any of the /assets/ folders and you should be good. You can read more about the public and assets folders here: Section 2 How to use the Asset Pipeline Let

Unable to get Rails 3.1, Compass, Sass, Blueprint working on Heroku Cedar

谁都会走 提交于 2019-12-03 15:56:54
For the most part I've followed the direction laid out here Which is resulted in the following error coming from the initializer it asked me to create: from /app/config/initializers/sass.rb:1:in `<top (required)>' 2011-09-05T16:45:42+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/railties- 3.1.0/lib/rails/railtie/configuration.rb:78:in `method_missing': undefined method `sass' for # <Rails::Application::Configuration:0x00000003845528> (NoMethodError) The Heroku page on getting started isn't much help either. It is basically the same instructions only without the initializer. However

Unicorn/Nginx process missing, socket open

我只是一个虾纸丫 提交于 2019-12-03 15:53:25
I am trying to deploy code using Capistrano, and it fails on deploy:start or deploy:stop because the Unicorn process is already killed. However if I try to cap deploy:start , I get a stderr claiming that Address already in use - /tmp/my_app.socket . How would this happen, and how might I get out of this mess? Still not sure how this happens, but the following solution seems to work: lsof /tmp/my_app.socket - lists the pids kill -9 pid - (replace 'pid' with one of those listed) Then cap deploy:start from the local terminal. 来源: https://stackoverflow.com/questions/10150245/unicorn-nginx-process

Rails: how to disable before_destroy callback when it's being destroyed because of the parent is being destroyed (:dependent => :destroy)

为君一笑 提交于 2019-12-03 15:14:31
问题 I have two classes: Parent and Child with Child: belongs_to :parent and Parent has_many :children, :dependent => :destroy The problem is that I want to check that there is always at least one child present, so I have a before_destroy method in Child that abort the destroy if it is the only child belonging to its parent. And, if I want to destroy the parent, it will call the before_destroy callback on every child, but when there is one child, it will abort the destroy, so the parent will never

rails 3.1.1 engines - with mountable engines, is it possible to access parent app assets, default layout?

北战南征 提交于 2019-12-03 14:53:18
This is more for experimentation - I am aware that I can do this with --full but I wanted the functionality of namespacing in the app to avoid conflicts The idea is to have a main app - which handles authentication, common items, admin screens etc Then creating engines to add further functionality like crm cms blog wiki forum etc These engines I can pick and choose as I need for whatever kind of app I am building. Is this possible? Is it just the case of applying both --mountable and --full options? Experimenting - would there be any issue if I use the full option add rspec and then simple add

security safe to disable csrf tokens for json rails calls?

假装没事ソ 提交于 2019-12-03 14:45:38
I have an existing rails backend website which makes json calls to server. Now,I am developing a mobile iOS app to use the same backend and send calls in json. However, mobile requests are failing with: WARNING: Can't verify CSRF token authenticity Searching around stackoverflow, many suggested to disable csrf checks for json calls by using something like this: # Or this in your application_controller.rb def verified_request? if request.content_type == "application/json" true else super() end end But my question is , I dont understand how does this prevent csrf attacks in json format? Attacker

Thinking sphinx doesn't start - “Failed to start searchd daemon”

拟墨画扇 提交于 2019-12-03 14:08:49
I try to start thinking sphinx on my server but it doesn't want to work. I do: $ rake thinking_sphinx:index && rake thinking_sphinx:start And i get: Generating Configuration to /vol/www/apps/ror_tutorial/releases/20120202111730/config/development.sphinx.conf Sphinx 2.0.3-release (r3043) Copyright (c) 2001-2011, Andrew Aksyonoff Copyright (c) 2008-2011, Sphinx Technologies Inc (http://sphinxsearch.com) using config file '/vol/www/apps/ror_tutorial/releases/20120202111730/config/development.sphinx.conf'... indexing index 'micropost_core'... WARNING: collect_hits: mem_limit=0 kb too low,