Always getting 401 Unauthorized with new install of Rails + Devise

Well this little exercise in frustration turned out to be a good lesson in RTFM. I had set up Devise with confirmable, and when I created my layouts I neglected to insert the following lines: <p class=”notice”><%= notice %></p> <p class=”alert”><%= alert %></p> … as it clearly states to do in the getting started guide. … Read more

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

How to Implement ajax pagination with will_paginate gem

Create a new helper (ex. app/helpers/will_paginate_helper.rb) with the following content: module WillPaginateHelper class WillPaginateJSLinkRenderer < WillPaginate::ActionView::LinkRenderer def prepare(collection, options, template) options[:params] ||= {} options[:params][‘_’] = nil super(collection, options, template) end protected def link(text, target, attributes = {}) if target.is_a? Fixnum attributes[:rel] = rel_value(target) target = url(target) end @template.link_to(target, attributes.merge(remote: true)) do text.to_s.html_safe end end end … Read more

Sass import error in Rails 3 app – “File to import not found or unreadable: compass”

I was getting this error. I changed this line in my application.rb from: Bundler.require(:default, Rails.env) if defined?(Bundler) to: Bundler.require(*Rails.groups(:assets => %w(development test))) if defined?(Bundler) Also, make sure the files are names something.css.sass NOT something.sass And one other thing, I had an old compass.rb file in my config directory which isn’t needed in Rails 3.2. Deleting … Read more