ruby-on-rails-3.2

how to hook for destroy of a model that belongs to another model?

巧了我就是萌 提交于 2019-12-23 12:51:48
问题 I have a User model which has_many experiments: class User < ActiveRecord::Base has_many :experiments, :dependent => :destroy and Experiment model: class Experiment < ActiveRecord::Base belongs_to :user has_attached_file :thumbnail I want to hook for destroy moment at the Experiment model after the owner User get destroyed. (ex user cancel his account) I need to do so to delete the attachment image of the Experiment model, which is stored at amazon. like experiment.thumbnail.destroy What is

How can i use accepts nested attributes with the HABTM?

試著忘記壹切 提交于 2019-12-23 09:47:47
问题 I have two models User and Category. class User < ActiveRecord::Base has_and_belongs_to_many :categories accepts_nested_attributes_for :categories end similarly class Category < ActiveRecord::Base has_and_belongs_to_many :users end i have a requirement where i have to add the categories to the categories table and add the reference so that i can get the categories related to user but if another user enters the same category then i have to make use of the id instead of creating new one. How

rails 3.2 development mode is not displaying the full error page with backtrace etc

我与影子孤独终老i 提交于 2019-12-23 09:36:40
问题 I just upgraded to rails 3.2 Everything is working fine except error pages no longer show the normal development debug info. Instead it's showing the standard production error page (white background with red text in the middle: "We're sorry, but something went wrong. We've been notified about this issue and we'll take a look at it shortly." Is there a new setting or something I'm missing for rails 3.2? I've read over the upgrade instructions and do not see it mentioned anywhere. I tried

Rails 3.2.3 namespaced controllers being overridden by global controllers with same name

为君一笑 提交于 2019-12-23 08:29:12
问题 When the global application controller is loaded first, the namespaced application controller does not load when loading pages within that namespace. The application controller looks like this: class ApplicationController < ActionController::Base protect_from_forgery end And the namespaced application controller looks like this: class Admin::ApplicationController < ApplicationController def authenticate_admin! if current_admin.nil? redirect_to new_admin_session_url end end private def current

Rails 3.2.3 namespaced controllers being overridden by global controllers with same name

不想你离开。 提交于 2019-12-23 08:28:20
问题 When the global application controller is loaded first, the namespaced application controller does not load when loading pages within that namespace. The application controller looks like this: class ApplicationController < ActionController::Base protect_from_forgery end And the namespaced application controller looks like this: class Admin::ApplicationController < ApplicationController def authenticate_admin! if current_admin.nil? redirect_to new_admin_session_url end end private def current

1) PasswordResets emails user when requesting password reset

南笙酒味 提交于 2019-12-23 06:35:06
问题 I've been trying to add a password reset for users that forget their password. The users click on forgot password? on the sign up page. Then the user types their email and clicks reset password, which creates a token and sends an email with a link to reset their password. For the most part it works ONLY when the email box is blank or has exactly 6 random letter/numbers, but it doesn't work when a user puts in his email and clicks password reset, it brings up the error message: **Validation

Ruby on Rails gem 'byebug' installing error

泪湿孤枕 提交于 2019-12-23 05:34:13
问题 How can I fix this error? This issue is created when I check the rails version in a demo created website using this command. 回答1: you can also use another debugger gem 'pry', '0.9.12.6' and remove gem 'byebug' . Then run bundle install 回答2: The output in yellow is asking you to run bundle install instead of gem install You should do that. Update: It looks like the windows version build is failing. Only passes for ruby 2.0.0 but not for above versions. You can check the status at byebug's

How to list the users who LIKE a given Post

对着背影说爱祢 提交于 2019-12-23 05:06:40
问题 I am having trouble figuring out how to list all of the USERS who have LIKED a particular POST. Currently I am using: <span class="count"><%= dailypost.likes.count %></span> This has allowed me to count all of the LIKES associated with that particular POST.BUT it does not list the actual users. I have tried using this to list all of the USERS who LIKED that POST <%= dailypost.likes %> Instead I get back: [#<Like id: 360, dailypost_id: 306, user_id: 1, created_at: "2013-04-28 21:51:45",

Error trying to download using filnename format

荒凉一梦 提交于 2019-12-23 04:28:25
问题 I'm trying to customize the format when i'm saving to xls : I want help customizing= "Date" + "ejecutive selected" + ".xls" But is not working My models class Policy < ActiveRecord::Base unloadable belongs_to :ejecutive has_many :policy def self.search(search) if search find(:all, :conditions => ["ejecutive_id = ? ", search.to_i ] ) else find(:all) end end end class Ejecutive < ActiveRecord::Base has_many :policies end Here is my controller. Here i put my format that i'm trying to customize

Creating has_many association with ancestry gem

倖福魔咒の 提交于 2019-12-23 04:26:56
问题 I installed ancestry gem & create Location Structure. Alaska California Los Angeles Fresno Cincotta (Fresno) Hammond (Fresno) Melvin (Fresno) Melvin 1 Melvin 2 Melvin 3 Arizona Colorado My post and location model class Location < ActiveRecord::Base include Tree has_many :posts end class Post < ActiveRecord::Base belongs_to :location end When i am add new post, how to display only depth 4 level ( Melvin 1,Melvin 2,Melvin 3 ) as drop down. 回答1: You have to enable cache depth so you can use at