ruby-on-rails-3

Active admin redirects after login

浪尽此生 提交于 2019-12-23 18:11:21
问题 When an admin logs in, it automatically redirects to the main home page (i.e. not the admin dashboard). I'm not sure why it does this or how to change it... routes.rb ActiveAdmin.routes(self) devise_for :admin_user, ActiveAdmin::Devise.config get "guidelines/topic" get "guidelines/topichospital" get "guidelines/topicspecialty" get "guidelines/favourite" get "profiles/show" get "guidelines/show" root :to => 'guidelines#index' my application_controller.rb has been changed to redirect after user

Rails3 Mysql2::Error: Unknown column - ActiveRecord::StatementInvalid

倖福魔咒の 提交于 2019-12-23 18:09:44
问题 I'm new to working with databases in Rails at this level, and I've looked for several hours but haven't found a solution to this specific problem. Versions: Rails 3.2.9, Ruby 1.9.3, MySQL 5.5.28 (mysql2 gem 2.9.0), Mac OS 10.7.5 Error: ActiveRecord::StatementInvalid in Action_figures#list Mysql2::Error: Unknown column 'action_figures.position' in 'order clause': SELECT `action_figures`.* FROM `action_figures` ORDER BY action_figures.position ASC Extracted source (around line #14): [list.html

accessing rails models from rake task

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 17:54:45
问题 How can I access model objects from rails rake task? If I initialize my rufus scheduler $scheduler = Rufus::Scheduler.start_new in my rake would that scheduler stay alive since it's from a rake task? 回答1: To access a rails model in your rake task you need to load the :environment. task :my_task => [:environment] do User.new #... end You would not call the scheduler within a task but the other way around. You need to start a Rufus scheduler and then call your rake tasks from them. You need to

“Invalid gemspec” messages during “bundle install” of factory girl (rails 3.1 and ruby 1.9.2p290)

孤者浪人 提交于 2019-12-23 17:18:51
问题 Note: I asked this question when I got unexpected messages when doing bundle install with the factory_girl gem using Ubuntu 11.10. Being a noob I had ... and still have ... no idea what was going on. The update below attempts to outline what I did to eventually get rid of the messages. I am leaving the question around with a slightly more pertinent title line in case it might be of use to someone else. I look at Factory Girl's README.md and I see: Install gem install factory_girl or add the

How do I remove white space between HTML nodes?

瘦欲@ 提交于 2019-12-23 17:15:31
问题 I'm trying to remove whitespace from an HTML fragment between <p> tags <p>Foo Bar</p> <p>bar bar bar</p> <p>bla</p> as you can see, there always is a blank space between the <p> </p> tags. The problem is that the blank spaces create <br> tags when saving the string into my database. Methods like strip or gsub only remove the whitespace in the nodes, resulting in: <p>FooBar</p> <p>barbarbar</p> <p>bla</p> whereas I'd like to have: <p>Foo Bar</p><p>bar bar bar</p><p>bla</p> I'm using: Nokogiri

why do I get the error when installing the gem 'pg'? [duplicate]

你。 提交于 2019-12-23 17:10:08
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: Unable to install pg gem on ubuntu - Can’t find the 'libpq-fe.h header I'm trying to add the gem pg to my local environment. But it returns this error Errno::EACCES: Permission denied - /Users/me/.rvm/gems/ruby-1.9.3-p362/gems/pg-0.14.1/.gemtest An error occurred while installing pg (0.14.1), and Bundler cannot continue. Make sure that `gem install pg -v '0.14.1'` succeeds before bundling. What should I do?

Rails: Belongs_to Polymorphic Association + conditions

坚强是说给别人听的谎言 提交于 2019-12-23 17:10:04
问题 So I have this model: class Model < ActiveRecord::Base attr_accessible :to_id, :to_type belongs_to :to, polymorphic: true end I was wondering if I could add another relationship when belongs_to is on a specific type: class Model < ActiveRecord::Base attr_accessible :to_id, :to_type belongs_to :to, polymorphic: true belongs_to :to_user, :foreign_key => :to_id, :conditions => ['to_type = ?', 'User'] # doesn't work # OR MAYBE belongs_to :to_user, :foreign_key => :to_id, :foreign_class => 'User'

Rails 3, too many ways to test?

喜欢而已 提交于 2019-12-23 16:53:40
问题 If you were just starting out in rails which path would you encourage new users to go down with regards to Testing . Anything I read about regarding Rails 3, tells me I should be using Rspec 2 . But Rspec comes with a whole whack of other things I need to learn like gem 'capybara' gem 'database_cleaner' gem 'cucumber-rails' gem 'cucumber' gem 'spork' gem 'launchy' And then one of my friends just told me that I should just stick to the testing framework that comes with rails, and maybe just

Rails 3 routes: How to avoid conflict with 'show' action?

妖精的绣舞 提交于 2019-12-23 16:22:14
问题 I currently have the following routes set up for photos : resources :photos match 'photos/:user' => 'photos#user', :as => :user_photo match 'photos/:user/:key' => 'photos#show', :as => :show_photo Those two match routes give me URLs like: http://example.com/photos/joe_schmoe http://example.com/photos/joe_schmoe/123xyz ...similar to the way Flickr formats its URLs. The problem I'm having, though, is that the photos/:user route is either interpreted as the show method, or if I put those custom

after_commit callback is being called several times

只愿长相守 提交于 2019-12-23 16:07:07
问题 update: Is it the case that a call to update_attributes gets it's own transaction? I've looked at this question and for reasons in addition to that question, i've decided to go with after_commit as the proper hook. The problem is it's being called multiple (exactly three) times. The code is a little complex to explain, but basically there is a profile model that has include Traits::Blobs::Holder in holder.rb I have: module ClassMethods def belongs_to_blob(name, options = {}) clazz = options[