Rails 3 – upload files to public directory

a. Form <%= form_for :file_upload, :html => {:multipart => true} do |f| %> <%= f.file_field :my_file %> <%= f.submit “Upload” %> <% end %> b. controller def file_upload require ‘fileutils’ tmp = params[:file_upload][:my_file].tempfile file = File.join(“public”, params[:file_upload][:my_file].original_filename) FileUtils.cp tmp.path, file … # YOUR PARSING JOB FileUtils.rm file end But you can parse just tempfile, so … Read more

rails:3 Devise signup Filter chain halted as :require_no_authentication rendered or redirected

The mentioned line on Devise’s Controller makes sense in general cases: a logged in user can’t sign up. As you’re on a case where only an admin can create a user, I would suggest that you don’t use Devise’s controller on Registerable module and write your own controller with your own rules. You can write … Read more

Setting up a polymorphic has_many :through relationship

To create a polymorphic has_many :through, you must first create your models. We will use’Article,’ ‘Category,’ and ‘Tag’ where ‘Tag’ is the join-model and Article is one of many objects which can be “tagged” with a category. First you create your ‘Article’ and ‘Category’ models. These are basic models which do not need any special … Read more

Rails 3 – how do I avoid database altogether?

Rails 3: In application.rb, remove the require ‘rails/all’ line and instead add these lines: require “action_controller/railtie” require “action_mailer/railtie” require “active_resource/railtie” require “rails/test_unit/railtie” require “sprockets/railtie” Also see Remove ActiveRecord in Rails 3 and look into the Active Model railscast Rails 3.2.x: You’ll also need to remove/comment out this line in application.rb config.active_record.whitelist_attributes = true And remove/comment … Read more

How to rename rails 4 app?

Since rails 4.1.x, if you want to rename your application, the only two files you need to modify are config/application.rb: require File.expand_path(‘../boot’, __FILE__) require ‘rails/all’ # Require the gems listed in Gemfile, including any gems # you’ve limited to :test, :development, or :production. Bundler.require(*Rails.groups) module YourApplicationName # <– rename it here class Application < Rails::Application … Read more

Error “…cannot load such file — mysql2/2.0/mysql2 (LoadError)”. On Windows XP with Ruby 2.0.0

Had the absolutely same issue on Windows 7 x64 with Ruby 2.0.0 and DevKit 4.7. The following steps helped me. gem uninstall mysql2 Download last MySQL connector from http://cdn.mysql.com/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip Extract it to C:\connector-6.0.2 gem install mysql2 –platform=ruby — ‘–with-mysql-lib=”C:\connector-6.0.2\lib” –with-mysql-include=”C:\connector-6.0.2\include” –with-mysql-dir=”C:\connector-6.0.2″‘ Or even shorter: gem install mysql2 –platform=ruby — –with-opt-dir=”C:\connector-6.0.2″