ruby-on-rails-3.1

devise overriding registrations controller - uninitialized constant Users::RegistrationsController

爷,独闯天下 提交于 2019-11-30 17:34:11
I'm trying to override some the functionality of the default devise registrations controller so that only certain users can create accounts for others. So in a file called registrations_controller.rb under the controllers/users folder I have the following class Users::RegistrationsController < Devise::RegistrationsController before_filter :check_permissions, :only => [:new, :create, :cancel] skip_before_filter :require_no_authentication def check_permissions authorize! :create, resource end end and in my routes file I have devise_for :users, :controllers => { :registrations => 'users

ruby on rails add a column after a specific column name

落花浮王杯 提交于 2019-11-30 17:31:15
I tried to add a column to a table after a specific column in the table. Here is what I did: rails generate migration add_reaction_id_to_patient_allergies reaction_id: integer :after => 'patient_id' Here is what my migration file looks like: class AddReactionIdToPatientAllergies < ActiveRecord::Migration def change add_column :patient_allergies, :reaction_id, :string add_column :patient_allergies, :integer, :string add_column :patient_allergies, :, :after add_column :patient_allergies, :=, :string end end I dont think the command went well. I see an '=' in the above file. I do not think it

How do you create prepared statements with the mysql2 gem?

那年仲夏 提交于 2019-11-30 17:29:43
I've tried using google to answer this seemingly simple question, but to my surprise, it didn't help. I have code in my rails application currently using the 'prepare' method with the mysql gem. On switching to mysql2, this breaks with the error: undefined method `prepare' for #<Mysql2::Client::0....... So I tried looking for a version of the 'prepare' method but this search has been unsuccessful so far. Can anyone help me out with this? Edit: If this isn't possible, could anyone let me know if there's a way to simply parameterize my queries with something in the mysql2 library? The mysql2 gem

How to call a parent app's helper method from a rails 3.1 engine

假如想象 提交于 2019-11-30 16:39:40
I'm building a rails engine that uses the "acts as" format to establish relationships with the parent application's User model. module Cornerstone module ActsAsCornerstoneUser extend ActiveSupport::Concern module ClassMethods def acts_as_cornerstone_user(options = {}) #= Associations has_many :cornerstone_discussions #= Options Cornerstone::Config.auth_with << options[:auth_with] if options[:auth_with] Cornerstone::Config.auth_with.flatten! end end module InstanceMethods end end ActiveRecord::Base.send :include, ActsAsCornerstoneUser end I would like for a developer to be able to specify a

sqlite3 varchar matching with “like” but not “=”

前提是你 提交于 2019-11-30 16:14:08
问题 Using Rails 3.1 and sqlite3 for development, test environments. Added a new table in a migration: create_table :api_keys do |t| t.string :api_key t.integer :user_id t.timestamps end This produces a table with the following schema: create_table "api_keys", :force => true do |t| t.string "api_key" t.integer "user_id" t.datetime "created_at" t.datetime "updated_at" end In ActiveRecord model: before_create :fill_api_key private def fill_api_key self.api_key = SecureRandom.hex(30) end ActiveRecord

CSS in Rails Asset Path not processed by ERB in development

假装没事ソ 提交于 2019-11-30 15:41:28
I have a Rails app with the following in /app/assets/stylesheets/styles.css.erb : ... #nestedbg { background-position: left top; background-image: url(<%= asset_path 'siteheader2.png' %>); background-repeat: repeat-x; background-attachment: fixed; } ... When I run rake assets:precompile and then run rails s -e production , everything works as expected. However, when I remove the precompiled assets and run rails s in development, the CSS file comes up as shown above instead of being properly substituted. I tried putting config.assets.compile = true in /config/environments/development.rb and

How can I use assets within Mailer?

我们两清 提交于 2019-11-30 15:40:29
问题 I have trouble using any form of the asset pipeline within mailer, wether the Mailer itself or the view. The following produces and empty src image tag. <%= image_tag "emails/header-general.png" %> The empty image tag looks like this: img alt="Header-general" The following form of attaching a file through the model and using it in the view attaches an empty image. attachments.inline['header.jpg'] = 'emails/header-general.png' ... <%= image_tag attachments['header.png'] %> I did check the path

OmniAuth Single Sign On with Devise, invalid_credentials

不想你离开。 提交于 2019-11-30 15:24:11
I have 3 web apps - A, B and C. App A contains the user database. If accessing App B and App C, I would like the user to be redirected to App A to be authenticated, and then be returned back to whichever app they tried to access. At the same time, they should be logged in to all apps. Unless anyone has a better solution, I have gone with an OmniAuth/Devise combo solution as described in this blog post . I have forked and updated to Rais 3.1.2 a sample App A and a sample app B/C. App A - Provider - https://github.com/RobZolkos/sso-devise-omniauth-provider App B/C - Client - https://github.com

Persisting SCSS variables in rails asset pipeline?

一世执手 提交于 2019-11-30 14:35:52
问题 I'm upgrading a rails app with lots of SCSS stylesheets to use the asset pipeline, and need to include some global variables and mixins for each file. Adding several @import directives at the top of every file isn't very DRY, so I'd like to do something like this: # application.css /* *= require variables *= require mixins *= require_tree . */ This doesn't work of course, because the variables are not persisted across files. Anyone know how to achieve this? 回答1: The default manifest syntax

Rendering a partial in assets

随声附和 提交于 2019-11-30 13:58:24
I'm using Ruby on Rails 3.1 and I'm wondering how I could render a partial in a javascript asset. What I'm aiming at: # in /app/assets/javascript/cart.js.coffee.erb $('a.add_sth').click -> $('.random_container').append('<%= render partial: 'way/to/partial' %>') This causes a NoMethodError: undefined method `render' for #<#<Class:0x007fc54584c6e8>:0x007fc5474cd470> If I write <%= 2+3 %> instead it works fine, btw. I think the problem is that the asset pipeline is independent from the default ActionView and that's why render() is unknown there. Anyway, is there a way to get that partial's