ruby-on-rails-3.1

Rails reset single column

自作多情 提交于 2019-12-10 18:55:49
问题 I am trying to implement a rake task that will run once a month to reset a single column. I would prefer to reset the column to its default value but I cannot find any methods to help me accomplish this. reset_column_information does not work What is the most efficient way to reset a single column in active record? 回答1: Base method #update_all does the update direct in the database, so it is very efficient. However it bypasses callbacks because the models aren't loaded: http://apidock.com

Nested forms in rails 3.1

孤街浪徒 提交于 2019-12-10 18:46:17
问题 I have a problem with nested forms: rails 3.1 doesn`t render fields_for blocks when it should (when editing existing record for example). Since I`m not confident enough in my english, I`ve made a small example app: New Action: def new @manga = Manga.new 3.times {@manga.volumes.build} end Form Code: <%= form_for @manga do |f| %> <%= f.error_messages %> <p> <%= f.label :name %><br /> <%= f.text_field :name %> </p> <% f.fields_for :volumes do |builder| %> <p> <%= builder.label :cover_link, "Link

Intermittent “premature end of script headers” with Rails 3.1

时光总嘲笑我的痴心妄想 提交于 2019-12-10 18:35:49
问题 So I've started upgrading our app to Rails 3.1 from Rails 3.0.9. It's working great in the development environment. The time has come to put it up onto the staging server so we can run some full acceptance tests -- but oh, no! We're getting the horrible " Internal Server Error " pages served back at us half of the time, seemingly randomly. We're using Ruby 1.9.2 (p290) Apache (2) and Passenger (3.0.9). Absolutely nothing is being written to our app's log file when these happen (even at the

Precompile failing on Heroku with initialize_on_precompile set to false

你离开我真会死。 提交于 2019-12-10 17:55:27
问题 I have an app I'm trying to deploy to Heroku's cedar stack. During the precompile phase of the deploy, I get the error: Your bundle is complete! It was installed into ./vendor/bundle Cleaning up the bundler cache. -----> Writing config/database.yml to read from DATABASE_URL -----> Preparing app for Rails asset pipeline Running: rake assets:precompile rake aborted! could not connect to server: Connection refused Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port

Rails 3.1 Sqlite3 Error On Push To Heroku

本秂侑毒 提交于 2019-12-10 17:28:44
问题 I have a rails 3.1 app that i am trying to push to Heroku. It keeps failing when i push it. Installing sqlite3 (1.3.4) with native extensions Unfortunately, a fatal error has occurred. Please report this error to the Bundler issue tracker at https://github.com/carlhuda/bundler/issues so that we can fix it. Thanks! /usr/local/lib/ruby/1.9.1/rubygems/installer.rb:483:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError) /usr

What would the joining table called in this case in Rails 3.1?

北慕城南 提交于 2019-12-10 17:28:32
问题 I have two tables with has_and_belongs_to_many relationship: categories and raw_categories Should the table be called categories_raw_categories ? 回答1: Yes, the join table is named after the two tables to be joined listed in alphabetical order. Since categories is higher in the alphabet than raw_categories , the join table is called categories_raw_categories . Note that if you are doing migrations, you need to create a separate migration for this join table. See here for more details on HABTM

Price gets multiplied by 100 when saving product in Spree (RoR)

梦想的初衷 提交于 2019-12-10 17:27:31
问题 I installed the online shopping framework Spree on top of Rails 3.1.3 and Ruby 1.9.3. I also use the Spree_i18n gem to localize the shop. Now, whenever I save a product, the price is multiplied by 100. For example, in the admin area, I type the price 3.20. That results in the value 320. If I save again, it changes to 32000 and so on. Here is my localized de_numbers.yml for reference: --- de: number: currency: format: format: "%u%n" unit: "€" precision: 2 separator: '.' delimiter: ',' I can

How do I initialize ActionDispatch::ParamsParser in Rails 3.1?

会有一股神秘感。 提交于 2019-12-10 17:26:19
问题 My application defines a custom Mime type for its Rest interface. So I register it in the mime_types.rb initializer: Mime::Type.register "application/vnd.example.app-v1+xml", :xml_v1 and Rails correctly handles the respond_to blocks in the controllers. However, I still need to tell Rails that incoming requests should be parsed as an XML, using ActionDispatch::ParamsParser. I just don't know how to use it inside an initializer. What's the correct way? 回答1: This works well: Mime::Type.register

Asset Precompile on the development machine before capistrano deployment

心已入冬 提交于 2019-12-10 17:18:06
问题 I want the asset precompile to happen on my dev machine beofore the code is packed (tar ball'ed) by capistrano and have the precompiled assets already included in the final deployment package. When I try the inbuilt capistrano recipe thats in load 'deploy/assets' it runs rake RAILS_GROUPS=assets assets:precompile on the server. The reason I am looking for this because at the moment the precompile is taking too long on my EC2 micro-instance (and also at times just hangs), It would great if

Rails redirect to page user wanted to view prior to login

北城余情 提交于 2019-12-10 17:13:48
问题 I'm trying to redirect users back to a page that they were trying to access prior to logging in (the page is only viewable to users). I'll start off with a before filter that targets my trip new action: before_filter :authenticate, :only => [:new, :create, :edit, :update, :destroy] def authenticate deny_access unless signed_in? end def deny_access store_location redirect_to login_path, :notice => "Please log in to access this page." end def store_location session[:return_to] = request