ruby-on-rails-3.1

Encoding issues in javascript files using rails asset pipeline

主宰稳场 提交于 2019-12-01 00:14:19
问题 I'm using rails 3.1 and the asset pipeline (ruby 1.9.2). I get the following error when trying to serve a javascript js.erb file that has utf-8 encoded strings invalid byte sequence in US-ASCII I've set Encoding.default_external = "UTF-8" in my environment.rb file. How do i get the asset pipeline to serve with a different encoding? EDIT The error only shows up when I'm generating the utf-8 character outside of the file (in this case by querying from the DB). The error goes away if I add <% "日

Rails 3.1 on Ubuntu 11.10 under VirtualBox very slow

℡╲_俬逩灬. 提交于 2019-11-30 22:36:10
I have VirtualBox with Ubuntu 11.10 on Windows7. I run Rails 3.1 on webrick (rails s) and go to VirtualBox's IP adress (192.168.2.xxx:3000) from browser on Windows. At this moment I face troubles - page loads very very slowly, on Rails console i see how slowly it responses files (css, js, images): up to 5 seconds for each! But: if I go 0.0.0.0:3000 inside Ubuntu - it works perfect. Where is the problem? Where to look for a solution? As mentioned above, it appears this is a duplicate of another issue, though that issue specifically mentions webrick and a remote desktop connection, neither of

Rails - Devise, how can I disable some default routes?

折月煮酒 提交于 2019-11-30 21:33:32
问题 I want to completely disable the routes /users/sign_in for get and post. I was able to successfully override them using the following: devise_for :users do get "/admin" => "devise/sessions#new", :as => :new_user_session post "/admin" => "devise/sessions#create", :as => :user_session end And when I run rake routes I see the following: new_user_session GET /admin(.:format) {:controller=>"devise/sessions", :action=>"new"} user_session POST /admin(.:format) {:controller=>"devise/sessions",

Images in rails 3.1 - moving to production

蓝咒 提交于 2019-11-30 21:11:34
问题 My articles have images. I put the images in app/assests/images and store their location in a field in the database. Then I can display them in by using: <%= image_tag(@article.image) %> But when I move to the production server, none of my images show up! The server's looking for assets/blank-d5dd6e3683b4753dfde3c70cf61f99b6.png rather than blank.png and it isn't available. How do I sort this? 回答1: This is a problem I ran into when Rails 3.1 was released. Normal assets If your assets are

Formastic Bootstrap Rails Error- No Such File to Load ButtonsHelpers

为君一笑 提交于 2019-11-30 20:27:38
I'm completely stuck on this error. Using Rails 3.1 trying to implement Formastic Bootstrap gem and getting error: `': no such file to load -- formtastic/helpers/buttons_helper (LoadError) Application.css *= require formtastic *= require formtastic-bootstrap Gemfile group :assets do gem 'sass-rails', " ~> 3.1.0" gem 'coffee-rails', "~> 3.1.0" gem 'uglifier' gem 'less-rails-bootstrap' gem 'bootstrap-sass' end formastic.rb Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder gem 'formtastic' gem 'formtastic-bootstrap' buttons_helper module FormtasticBootstrap module Helpers

Passing ActionView::Helpers::FormBuilder to a partial

拟墨画扇 提交于 2019-11-30 20:21:40
I am atempting to dinamically create form elements given a certain AJAX request. This is my setup: View: <%= link_to 'Next', check_unique_id_students_path, :remote => true %> <div id="guardian_student_details"></div> Controller: def check_unique_id @student = Student.new @this_form = ActionView::Helpers::FormBuilder.new(:student, @student, @template, {}, proc{}) end JS: jQuery("#guardian_student_details").html("<%=escape_javascript(render :partial => "student_details", :locals => { :s => @this_form }) %>"); Partial: <% puts s.text_field :first_name %> <% puts s.field_helpers %> For debugging

ActiveRecord::StatementInvalid: PG::Error: ERROR: null value in column “id” violates not-null constraint

为君一笑 提交于 2019-11-30 20:12:08
I am getting the following error frequently in my application. If I restart my rails application this error will not appear for some time. Rails - 3.1.3 Ruby - 1.9.3 ActiveRecord::StatementInvalid: PG::Error: ERROR: null value in column "id" violates not-null constraint Directory.create(:name=>"name",:alias_name=>"name",:site_id=>2,:type=>"Directory") (0.3ms) BEGIN SQL (0.8ms) INSERT INTO "databases" ("alias_name", "created_at", "created_by", "id", "name", "site_id", "type", "updated_at", "updated_by") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) [["alias_name", "name"], ["created_at", Wed, 17

“ActionView::Template::Error ( isn't precompiled)” raised on “image_tag nil”

萝らか妹 提交于 2019-11-30 18:57:50
If I don't handle view correctly, Production environment show 500. <%= image_tag post.user.image_url %> This could be <%= image_tag post.user.image_url if post.user && post.user.image_url %> but I am little careless and forgot this issue several times. How can I prevent this? How can I use <%= image_tag nil %> in production environment without raising 500? image_tag must have a source, Rails can do nothing with it, but raise an exception. You can write a helper like this: module ApplicationHelper def safe_image_tag(source, options = {}) source ||= "default.jpg" image_tag(source, options) end

Is COMB GUID a good idea with Rails 3.1 if I use GUIDs for primary keys?

六眼飞鱼酱① 提交于 2019-11-30 18:24:49
问题 I'm using Rails 3.1 with PostgreSQL 8.4. Let's assume I want/need to use GUID primary keys. One potential drawback is index fragmentation. In MS SQL, a recommended solution for that is to use special sequential GUIDs. One approach to sequential GUIDs is the COMBination GUID that substitutes a 6-byte timestamp for the MAC address portion at the end of the GUID. This has some mainstream adoption: COMBs are available natively in NHibernate (NHibernate/Id/GuidCombGenerator.cs). I think I've

Use windows or linux to start work with Ruby On Rails?

我们两清 提交于 2019-11-30 18:20:55
I'm new to Ruby On Rails and I want to know which is better to use for work with it. Windows or Linux. I've never worked with Linux before but I heard It's better to work with it. Is it necessary for someone like me to install linux or I can use windows and the results will be same with linux? If your current dev machine is running Windows, and you don't have access to a Linux environment right now, don't let that stop you from getting started with Rails. Definitely , definitely , definitely install the DevKit first thing (if it's not included in RubyInstaller yet). See https://github.com