ruby-on-rails-3.1

Rails 3.1 Mountable Engines : How to use/template it inside another application?

回眸只為那壹抹淺笑 提交于 2019-12-06 02:32:40
问题 Let's say I created a mountable engine called 'Soho' that has a controller for 'Users'. I can go to /users/1 to see my user with ID 1. Inside 'Soho', I have a application.html.erb for layout. Now let's assume I want to "blend" my engine 'Soho' in an application called 'Soho_test', and I mount my engine at "/". So, in my host application 'Soho_test', I can also go at /users/1 to see my user with ID 1. This is working. My question is : how can I do in my host application 'Soho_test' to apply

Undelete acts_as_paranoid deleted user on devise sign in

拜拜、爱过 提交于 2019-12-06 01:22:23
I have a Rails 3.1.3 app which uses devise for users authentication and soft-deletes them with acts_as_paranoid . I want the accounts to be undeleted upon password recreation, user sign up and user sign in, so if they provide a deleted email, I grab that account, make it live again, and then continue with the action (password recreation, or sign in). But in the Users::SessionsController#create action, after undeletion of the user it gets an Unauthorized error (but the user should now be visible). The code is: def create # Take into account acts_as_paranoid deleted users resource = resource

How to mock/stub the config initializer hash in rails 3

对着背影说爱祢 提交于 2019-12-06 00:53:36
Environment : Rails 3.1.1 and Rspec 2.10.1 I am loading all my application configuration through an external YAML file. My initializer (config/initializers/load_config.rb) looks like this AppConfig = YAML.load_file("#{RAILS_ROOT}/config/config.yml")[RAILS_ENV] And my YAML file sits under config/config.yml development: client_system: SWN b2c_agent_number: '10500' advocacy_agent_number: 16202 motorcycle_agent_number: '10400' tso_agent_number: '39160' feesecure_eligible_months_for_monthly_payments: 1..12 test: client_system: SWN b2c_agent_number: '10500' advocacy_agent_number: 16202 motorcycle

Can multiple objects be inserted with the << operator in Rails 3.1?

偶尔善良 提交于 2019-12-06 00:29:39
Could I write the following ... raw_data.categories.each do |category| obj.categories << category end As the following instead? ... obj.categories << raw_data.categories obj.categories |= raw_data.categories BM5k Take a look at Array#<< and Array#push . Array#<< takes one which is appended in place to given array. For example: irb> array = %w[ a b c ] # => ["a", "b", "c"] irb> array << 'd' # => ["a", "b", "c", "d"] however, if you pass an array, you'll be surprised at the result irb> array << ['e', 'f', 'g'] # => ["a", "b", "c", "d", ["e", "f", "g"]] Array#push can handle 1+ objects, each of

Running spec for a rails engine from its parent app

耗尽温柔 提交于 2019-12-05 23:17:05
问题 I have rspec suite for parent app, and also some spec for engines attached. What I want is to run them with one command. Is there a way to include my gems paths into rspec load path? Or should I write rake task for this? 回答1: I think this is an interesting question, but my opinion is that Rails Engines should be treated as an independent code base and therefore not tested in your parent app. The effect is that you'd treat a Rails Engine in your parent app much like you treat other gems (EG,

How do I apply an 'active' class to my navigation based on the current_page in a DRY way? - Rails 3

耗尽温柔 提交于 2019-12-05 22:23:24
So in my application.html.erb I have my navigational structure that looks something like this: <div id="navigation"> <ul class="pills"> <% if current_page?(:controller => 'welcome', :action => 'index') %> <li><%= link_to "Profile", vanity_path(:vname => current_user.username) %></li> <li><%= link_to "Settings", settings_path %></li> <li><%= link_to "Sign Out", signout_path %></li> <% elsif !current_page?(:controller => 'welcome', :action => 'index') %> <li><%= link_to "Home", root_path %></li> <li><%= link_to "Profile", vanity_path(:vname => current_user.username) %></li> <li><%= link_to

Rails 3.1 asset pipeline vendor/assets folder organization

隐身守侯 提交于 2019-12-05 20:18:43
问题 I'm using the jQuery Tools scrollable library in my Rails 3.1 site with the various assets placed in the vendor/assets folder and it works great. My question is regarding the best way to organize the various files under vendor/assets. What is the recommended way to organize vendor/assets subfolders? Currently I have this structure: vendor/assets/ |-- images/ | |-- scrollable/ | <various button/gradient images> |-- javascripts/ | |-- scrollable/ | jquery.tools.min.js |-- stylesheets/ | |--

pdfkit not rendering correctly in rails 3.1

自作多情 提交于 2019-12-05 19:48:47
I have followed the following railscast about adding pdfkit to an application, and I am having some issues with the generation of pdfs. Here are the following things that I have done: I downloaded wkhtmltopdf via the homebrew package manager brew install wkhtmltopdf Then I added the pdfkit gem to my gemfile and ran the bundle install command. I added the following to my config/application.rb file require 'pdfkit' ... config.middleware.use PDFKit::Middleware, :print_media_type => true I then changed my application layout file to include all stylesheet types. If I run rake middleware, the

Rails 3.1 distinct find and missing attributes

眉间皱痕 提交于 2019-12-05 16:19:02
class State < ActiveRecord::Base has_many :cities end class City < ActiveRecord::Base belongs_to :state has_many :companies end class Company < ActiveRecord::Base belongs_to :city end I'm trying to list all states, and their respective cities, that contain at least one company registered. My first try was the following query: states = State.joins(:cities => :companies).includes(:cities) Which works, but I end up getting duplicates if a state has more than one city with companies in it. I then changed the query to: states = State.joins(:cities => :companies).includes(:cities).select("distinct

“Can't mass-assign protected attributes” with nested attributes

给你一囗甜甜゛ 提交于 2019-12-05 16:13:46
I've seen other questions with this problem, but so far the answers haven't worked for me. I'm trying to have a form that registers a User, and creates an Organization at the same time. The User and Organization are associated via an assignment table. Here is my form: = form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| = devise_error_messages! = f.fields_for :organizations do |f| = f.label :name = f.text_field :name = f.label :email = f.email_field :email = f.label :password = f.password_field :password = f.label :password_confirmation = f.password_field