ruby-on-rails-3.1

Disabling asset fingerprinting with asset_path for a single asset

瘦欲@ 提交于 2019-12-03 11:49:10
I want to use the normal asset name, e.g. app.js when calling the asset_path helper in my views. In production, it uses the cache-busting name, e.g. app-f73cf13e6f100eda6681381e7d3ae9eb.js . Is there a way to get the normal name using asset_path ? Calvin Figured it out, pretty simple actually. Just have to add digest: false to asset_path like so: asset_path('app.js', digest: false) By default assets.digest is enable in production environment and is recommended for several reasons. However, if you really want to disable it write this in your production.rb config.assets.digest = false For more

Annotate gem and rails 3.1

给你一囗甜甜゛ 提交于 2019-12-03 10:43:09
问题 Does anyone have any idea why annotate does not work anymore in rails 3.1 ? When trying to run it with : $ rvmsudo bundle exec annotate --position before and given I've got the following in my gemfile: gem "annotate", '2.4.0' I get the following error: /usr/local/rvm/gems/ruby-1.9.2-p180@rails31/gems/activerecord-3.1.0/lib/active_record /railties/databases.rake:3:in `<top (required)>': undefined method `namespace' for main:Object (NoMethodError) I'm using RVM with a gemset dedicated to rails

simple_forms custom data attribute

ⅰ亾dé卋堺 提交于 2019-12-03 10:34:34
问题 I would like to have an additional data attribute on an input tag generated by simple_form. The following does not work: <%= f.input :date, :as => 'date_picker', :data => {:datepicker => :datepicker} %> How could this be done? Is it possible at all? As you might have guessed: I am trying to add bootstrap-datepicker to my site without using explicit js to initialize the date picker. 回答1: The correct API is: f.input :date, :as => 'date_picker', :input_html => { :data => {:datepicker =>

How do I get escape_javascript and other helpers in my sprockets pre-processed js file (not a view)?

只愿长相守 提交于 2019-12-03 10:30:38
I'm using Rails 3.1 and the sprockets stuff. I want to use ERB to pre-process a js file that will then be included using javascript_include_tag. It is generated from code, and so I'm pre-processing it with ERB, but I can't get to the helpers like escape_javascript from ActionView::Helpers::JavaScriptHelper Say my file is called dynamic.js.erb, and it contains obj = { name: "test", tag: "<%= escape_javascript( image_tag( "logo.png" ) )%>" }; How do I stop it from producing the error: throw Error("NoMethodError: undefined method `escape_javascript' for #<#<Class:0x1067da940>:0x116b2be18> (in

How to create a new DateTime object in a specific time zone (preferably the default time zone of my app, not UTC)?

守給你的承諾、 提交于 2019-12-03 10:25:00
I have set the time zone in /config/application.rb , and I expect all times generated in my app to be in this time zone by default, yet when I create a new DateTime object (using .new ), it creates it in GMT . How can I get it to be in my app's time zone? /config/application.rb config.time_zone = 'Pacific Time (US & Canada)' irb irb> DateTime.now => Wed, 11 Jul 2012 19:04:56 -0700 irb> mydate = DateTime.new(2012, 07, 11, 20, 10, 0) => Wed, 11 Jul 2012 20:10:00 +0000 # GMT, but I want PDT Using in_time_zone doesn't work because that just converts the GMT time to PDT time, which is the wrong

Rails 3.1 with Asset Pipeline, link_to :confirm message showing twice?

江枫思渺然 提交于 2019-12-03 10:23:38
Okay, so I've seen this question about this problem being caused by multiple linkings of jQuery or Prototype, but I can confirm that I'm only linking to jQuery once on the entire page. My problem is this: when I have a link_to that confirms a deletion, the popup shows twice. Here's the applicable code in my template (written in Slim): link_to('Destroy', depot_path(@depot.id), :confirm => "Really?", :method => :delete) I'm running Rails 3.1.0 with the Asset Pipeline turned on, with gem 'jquery-rails' in my Gemfile , and the following is in my application.js file (which is compiled by Sprockets

ERROR NoMethodError: undefined method `debug_rjs=' for ActionView::Base:Class

放肆的年华 提交于 2019-12-03 10:23:36
This project was built with rails 3.0.9. Now i updated the gems and Gemfile => source 'http://rubygems.org' gem 'rails', '3.1.1' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'pg' gem 'devise' gem "will_paginate" gem 'ruby-debug19' gem 'rack', '1.3.3' gem 'jquery-rails' After rails s, when i do , http://0.0.0.0:3000/ i get this error => => Booting WEBrick => Rails 3.1.1 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server [2011-10-10 17:50:23] INFO WEBrick 1.3.1 [2011-10-10 17:50:23] INFO

How to create popup window to create new record in rails 3

有些话、适合烂在心里 提交于 2019-12-03 10:05:27
问题 We have a requirement where the web page displays all the records from joining few tables. We have an "Add Button" - upon clicking the button, I have to display an popup window, where user will enter the necessary details. The popup will have two buttons Save and Cancel. Clicking Save button, should validate the fields and if all validations are passed, then save the record to database else display the error messages in alert boxes. Clicking Cancel button will close the popup window. How do I

Tableless model in rails 3.1

霸气de小男生 提交于 2019-12-03 09:57:24
问题 Looks like this method doesn't work anymore in rails 3.1. So, does someone have a working solution? Actually, I've found this gist. It solves problems with columns_hash and column_defaults errors from the railscast's solution but I get ActiveRecord::ConnectionNotEstablished error all the time when I try to write some attribute. Any thoughts? 回答1: You should create your own model class and mix in the parts of ActiveModel (for example, validations) that you require. This blog post from Yehuda

What is the new format for rake tasks? (task :t, arg, :needs => [deps] versus task :t, [args] => [deps])

血红的双手。 提交于 2019-12-03 09:55:21
I'm using Rails 3.1 beta with Ruby 1.9.2 and rake 0.9.2, and have a bunch of rake tasks I've written. Here is an example: namespace :data do desc "dump the nodes and edges for a graph" task :dump_graph, :species_id, :needs => :environment do |t,args| args.with_defaults(:species_id => 'Hs') # ... end end When my rails app loads these rake tasks, however, I now get the following warning repeated once for each rake task: at /home/user/railsapp/lib/tasks/data/dump_graph.rake:3:in `block in <top (required)>' WARNING: 'task :t, arg, :needs => [deps]' is deprecated. Please use 'task :t, [args] =>