ruby-on-rails-3.2

How to setup bootstrap-datepicker-rails?

大憨熊 提交于 2019-11-30 18:13:01
Anybody knows how to setup the gem bootstrap-datepicker-rails? I followed the steps in http://rubydoc.info/gems/bootstrap-datepicker-rails/0.6.21/frames , basically: I setup twitter-bootstrap-rails gem I add this to gemfile gem 'bootstrap-datepicker-rails', '>= 0.6.21' Add this line to app/assets/stylesheets/application.css *= require bootstrap-datepicker Add this line to app/assets/javascripts/application.js //= require bootstrap-datepicker Add this line to app/assets/javascripts/controllername.js.coffee $('.datepicker').datepicker() Finally use in view :) <input type="text" data-behaviour=

ruby on rails: radio buttons for collection select

寵の児 提交于 2019-11-30 17:39:18
问题 I have a collection select: <%= f.collection_select :role, User::ROLES, :to_s, :humanize %> What is the radio button for this method? Thanks 回答1: There is no such helper in Rails 3. In Rails 4, it is collection_radio_buttons. 回答2: This way.. <%= f.collection_radio_buttons :role, User::ROLES %> 回答3: No documentation found for the form builder, but this should work: <%= f.collection_radio_buttons :my_attribute, my_hash.map {|k,v| [k,v]}, :first, :last do |b| %> <div class='my-class'> <%= b

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

Rails console default environment

穿精又带淫゛_ 提交于 2019-11-30 13:47:25
问题 On my development machine: $ bundle exec rails console Loading development environment (Rails 3.2.3) 1.9.3p194 :001 > Rails.env => "development" This is expected. So far, so good. Yet on my production server (to which I have deployed using Capistrano), I get exactly the same result: $ bundle exec rails console Loading development environment (Rails 3.2.3) 1.9.3p194 :001 > Rails.env => "development" On either machine, I can instead do: $ bundle exec rails console production Loading development

Print valid, non-escaped JSON in a view with Rails

半腔热情 提交于 2019-11-30 12:49:59
I've tried everything. Every combination of the helpers raw , html_safe to_json including some attempts with ::JSON.encode and CGI.unescape . The issue is that regardless of what I do, I can't print well-formed JSON in a view. It's always HTML escaped. Here's the code in my view: var campaignData<%= "=" + (raw @campaign.to_json) if @campaign %>; In my case, it's always the quotes that are escaped as ". I would just do a gsub on the quotes, but that is a terrible solution to what IMO ought to be a very simple, well documented use case. The problem here is with the "=" string. As it's considered

Does Amazon S3 need time to update CORS settings? How long?

你。 提交于 2019-11-30 12:31:00
Recently I enabled Amazon S3 + CloudFront to serve as CDN for my rails application. In order to use font assets and display them in Firefox or IE, I have to enable CORS on my S3 bucket. <?xml version="1.0" encoding="UTF-8"?> <CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <CORSRule> <AllowedOrigin>*</AllowedOrigin> <AllowedMethod>GET</AllowedMethod> <AllowedMethod>POST</AllowedMethod> <AllowedMethod>PUT</AllowedMethod> <MaxAgeSeconds>3000</MaxAgeSeconds> <AllowedHeader>*</AllowedHeader> </CORSRule> </CORSConfiguration> Then I used curl -I https://small-read-staging-assets

Rails: Could not authenticate you from Facebook because “Invalid credentials”

女生的网名这么多〃 提交于 2019-11-30 12:29:46
I integrated omniauth-facebook using https://github.com/plataformatec/devise/wiki/OmniAuth%3a-Overview . But I am getting error of : Could not authenticate you from Facebook because "Invalid credentials". And in logs, getting this: Authentication failure! invalid_credentials: OAuth2::Error, : {"error":{"message":"This authorization code has been used.","type":"OAuthException","code":100}} I have devise installed. When i click on facebook sign in link, it comes back to devise sign "www.mealnut.com/user/sign_in# = " and gives above error. I checked the solution for "Invalid credentials" on https

Nested attributes for belongs_to association rails

久未见 提交于 2019-11-30 11:45:39
I have two models, Complaint and Company. Complaint belongs_to and accepts_nested_attributes for Company, and Company has_many Complaints. # Models class Complaint < ActiveRecord::Base attr_accessible :complaint, :date, :resolved belongs_to :user, :class_name => 'User', :foreign_key => 'id' belongs_to :company, :class_name => 'Company', :foreign_key => 'id' has_many :replies accepts_nested_attributes_for :company end class Company < ActiveRecord::Base attr_accessible :name has_many :complaints, :class_name => 'Complaint', :foreign_key => 'id' has_many :branches, :class_name => 'Branch',

What is the purpose of vendor/bundle? Heroku tells me to remove it

半城伤御伤魂 提交于 2019-11-30 11:01:01
问题 Upon pushing some changes to Heroku, I noticed a warning about vendor/bundle (see WARNING below). What is the purpose of this directory if, according to the warning, it should be "removed" from Git tracking? Why isn't vendor/bundle automatically .gitignore 'd by default by Rails? Should I run bundle pack ? (Is it actually bundle package ??) What are the pros and cons around bundle pack (relative to both development and production )? To make this even more confusing, there's a popular blog

Too Few Arguments

♀尐吖头ヾ 提交于 2019-11-30 10:50:33
I am trying to get some Javascript working in my Rails app. I want to have my index page allow me to edit individual items on the index page, and then reload the index page upon edit. My index.html.erb page looks like: <div id="index"> <%= render 'index' %> </div> In my index.js.erb I have: $('#index').html("<%=j render 'index' %>"); and in my holders_controller: def edit holder = Holder.find(params[:id]) end def update @holder = Holder.find(params[:id]) if @holder.update_attributes(params[:holder]) format.html { redirect_to holders_path } #, flash[:success] = "holder updated") ## ^---Line 28