ruby-on-rails-3

how to run schema.rb?

家住魔仙堡 提交于 2020-08-21 10:06:28
问题 I'm trying to run db:migrate. This fails however because one of the tables that one of the migrations is trying to update does not exist. I searched the codebase and this table is created in db/schema.rb. How can I run schema.rb before db:migrate?? 回答1: Use the schema load task: rake db:schema:load From rake -T (expurgated version): rake db:schema:dump # Create db/schema.rb file usable with any AR-supported DB rake db:schema:load # Load schema.rb file into DB 来源: https://stackoverflow.com

How to timeout flash messages in rails

若如初见. 提交于 2020-08-21 06:14:20
问题 I currently have standard flash messages with the devise gem for success/failure etc. I have added the option to manually close the message with some bootstrap functionality via a close class. A small snippet is shown below. { <a class="close" data-dismiss="alert">×</a> <%= content_tag :div, msg, :id => "flash_#{name}" %> } I was would like to have an option to create a timeout period where the alert message would close on its one after 5 seconds. Not sure if there is a simple way to do this

How to get request's target controller and action with Rails 3?

一曲冷凌霜 提交于 2020-08-20 23:19:12
问题 In the application controller before filter. class ApplicationController < ActionController::Base before_filter :authenticate def authenticate # How do we know which controller and action was targetted? end end 回答1: class ApplicationController < ActionController::Base before_filter :authenticate def authenticate # How do we know which controller and action was targetted? params[:controller] params[:action] # OR controller.controller_name controller.action_name end end 回答2: In Rails 3.2 you no

Get name of the day

删除回忆录丶 提交于 2020-08-06 13:12:11
问题 how can I get the name of the day in Ruby. For eg. something like that: a = Date.today a.day_name => Tuesday the only thing i could find was .wday but that only returns for the number of the day in the week a.wday => 2 回答1: Time.now.strftime("%A") # => "Tuesday" or Date.today.strftime("%A") # => "Tuesday" 来源: https://stackoverflow.com/questions/29365439/get-name-of-the-day

“Couldn't find <object> without an ID”

末鹿安然 提交于 2020-07-05 09:58:12
问题 I'm having problems implementing a kind of comments form, where comments (called "microposts") belong_to both users and posts, users have_many comments, and posts (called "propositions") have_many comments. My code for the comments form is: <%= form_for @micropost do |f| %> <div class="field"> <%= f.text_area :content %> </div> <div class="actions"> <%= f.submit "Submit" %> </div> <% end %> The MicropostsController has this in the create action: def create @proposition = Proposition.find

Convert duration to hours:minutes:seconds (or similar) in Rails 3 or Ruby

China☆狼群 提交于 2020-07-04 05:29:09
问题 I have a feeling there is a simple/built-in way to do this but I can't find it. I have a duration (in seconds) in an integer and I want to display it in a friendly format. e.g. 3600 would be displayed as "01:00:00" or "1 hour" or something. I can do it with time_ago_in_words(Time.zone.now+3600) but that feels like a bit of a hack, there is no reason to add/subtract from the current time just to format this value. Is there a duration_in_words() or something? Thanks 回答1: See: http://api

Convert duration to hours:minutes:seconds (or similar) in Rails 3 or Ruby

馋奶兔 提交于 2020-07-04 05:27:48
问题 I have a feeling there is a simple/built-in way to do this but I can't find it. I have a duration (in seconds) in an integer and I want to display it in a friendly format. e.g. 3600 would be displayed as "01:00:00" or "1 hour" or something. I can do it with time_ago_in_words(Time.zone.now+3600) but that feels like a bit of a hack, there is no reason to add/subtract from the current time just to format this value. Is there a duration_in_words() or something? Thanks 回答1: See: http://api

Display has to many association activeadmin rails not working in staging but works fine in local and development

十年热恋 提交于 2020-06-29 10:36:33
问题 I have users which can have many identities, (depending on whether they login using facebook, google, or my site). In ActiveAdmin to display the identities I had the following code. ActiveAdmin.register User do menu label: 'Subscribers' ActiveAdmin.register Identity do belongs_to :user end index do selectable_column column :email column :current_sign_in_at column :sign_in_count column :created_at column "Sign-up Provider", :identities do |user| ul do user.identities.collect do |identity| li

Display has to many association activeadmin rails not working in staging but works fine in local and development

假装没事ソ 提交于 2020-06-29 10:36:27
问题 I have users which can have many identities, (depending on whether they login using facebook, google, or my site). In ActiveAdmin to display the identities I had the following code. ActiveAdmin.register User do menu label: 'Subscribers' ActiveAdmin.register Identity do belongs_to :user end index do selectable_column column :email column :current_sign_in_at column :sign_in_count column :created_at column "Sign-up Provider", :identities do |user| ul do user.identities.collect do |identity| li

Change database column type to decimal

笑着哭i 提交于 2020-06-29 05:59:05
问题 I am using Rails 3.2.3, and MySQL for my database I have created a model affiliate_payment.rb, with a column :amount , initially with datatype float . I tried to change this to a decimal with the following migration: class ChangeAffiliateIdAmountToDecimal < ActiveRecord::Migration def up change_column :affiliate_payments, :amount, :decimal end def down change_column :affiliate_payments, :amount, :float end end Ran rake db:migrate ... But when I check the column type to confirm, I find that