ruby-on-rails-3.1

What's the correct syntax for remove_index in a Rails 3.1.0 migration?

半腔热情 提交于 2019-12-02 17:49:14
I'm in the process of adding Devise to an existing Rails app, with a Users table already defined. The devise generator pushed out the following migration: class AddDeviseToUsers < ActiveRecord::Migration def self.up change_table(:users) do |t| ## Database authenticatable t.string :email, :null => false, :default => "" t.string :encrypted_password, :null => false, :default => "" ## Recoverable t.string :reset_password_token t.datetime :reset_password_sent_at ## Rememberable t.datetime :remember_created_at ## Trackable t.integer :sign_in_count, :default => 0 blah blah blah.... end add_index

How do I setup/use ruby on rails snippets and autocomplete in sublime text 2?

会有一股神秘感。 提交于 2019-12-02 17:43:54
I would appreciate if someone could direct me to a website that shows how to do this.. Can't seem to find anything decent enough via google. This will be the first time I'm doing this kind of thing with a text editor.. It has got to the stage where typing out things like <%= %> is getting old and slow. I've got a rails snippet package and also ryan-on-rails package installed. Just confused with how to start using them. I'm on max osx - snow leopard Kind regards Update This helped me out. http://webtempest.com/sublime-text-2-how-to-create-snippets/ but I still need a little practice. I have a

How to take screenshot of a website with Rails 3.1? — without using a service

南楼画角 提交于 2019-12-02 17:18:57
Almost every answer I've found references using some existing service. Is there a way to do this using Rails 3.1 programmatically? This was dead easy to do with PHP (there are prebuilt libraries in PHP that do this). What I'm looking to do, given a URL, is: Take a screenshot of the website Crop it (only take the top left most 100x100 pixels PS. Here is my environment: Rails 3.1 , Ruby 1.9.2 Note: The solution would probably need to follow any redirections on the URL as well. Updates: I've seen https://github.com/topfunky/osxscreenshot The problem is that it requires an older version of Ruby (1

Best place to store model specific constants in rails 3.1?

牧云@^-^@ 提交于 2019-12-02 17:13:16
I have a field type in a model called user which is an int in the db. The value of the int speficies the type of store it is. Example: 0 = mom 1 = dad 2 = grand mother and so on I have several other fields like this so it's overkill to create association tables. Instead of checking for those int values over the place in conditional statements in model and controller logic, is there a place in rails to store these constants. So that I could do this from my models and controllers? if myuser.type == MOM elsif myuser.type == GRAND_MOTHER EDIT: Solution I went with at the end: In model: # constants

Rails: about yield

岁酱吖の 提交于 2019-12-02 17:05:38
I saw some code in a Rails v2.3 app. In layout/car_general.html.erb (this view is called by a method in cars_controller) , I saw the code: <body> <%= yield %> <%= javascript_include_tag 'jquery-1.4.2.min' %> <% javascript_tag do %> <%= yield :jstemplates %> var some_car = new Object; <%= yield :some_car %> <% end -%> </body> Two questions to ask: Where can I find the yield content of the first <%=yield%> under <body> . Is it a rails specific way to include js code in a view by using <%= yield :jstemplates %> and what about <%= yield :some_car %> , is it point to a view or just to show the

Using RequireJS with a Rails 3.1 app

99封情书 提交于 2019-12-02 16:40:37
Question If you've used RequireJS with a Rails 3 (esp 3.1) app, how is that working for you? Any configuration tricks or other gotchas that I need to watch out for? Background I'm contemplating using RequireJS over the Sprockets-based Asset Pipeline in Rails 3.1, specifically for JavaScript code. I have two motivators for this choice: I want to leverage RequireJS' module management for my JS client-side code. I'd like a precompilation system that can follow my JS library code into other contexts. To my surprise, the Asset Pipeline precompiler is a baked-in part of Rails, not a part of

ActiveRecord objects in hashes aren't garbage collected — a bug or a sort of caching feature?

喜夏-厌秋 提交于 2019-12-02 16:38:19
I have a simple ActiveRecord model called Student with 100 records in the table. I do the following in a rails console session: ObjectSpace.each_object(ActiveRecord::Base).count # => 0 x = Student.all ObjectSpace.each_object(ActiveRecord::Base).count # => 100 x = nil GC.start ObjectSpace.each_object(ActiveRecord::Base).count # => 0 # Good! Now I do the following: ObjectSpace.each_object(ActiveRecord::Base).count # => 0 x = Student.all.group_by(&:last_name) ObjectSpace.each_object(ActiveRecord::Base).count # => 100 x = nil GC.start ObjectSpace.each_object(ActiveRecord::Base).count # => 100 #

REXML::Document.new can we give encode parameters on this line?

邮差的信 提交于 2019-12-02 16:36:34
问题 doc = REXML::Document.new file My code is failing at this point whenever my xml file contains some special characters other than UTF-8 . REXML::ParseException (#<REXML::ParseException: #<ArgumentError: invalid byte sequence in UTF-8> 回答1: You can call something like this REXML::Document.new(file.force_encoding("FILE_ENCODING").encode("UTF-8")) FILE_ENCODING is the encoding of your file variable. 来源: https://stackoverflow.com/questions/17194393/rexmldocument-new-can-we-give-encode-parameters

Array Attribute for Ruby Model

回眸只為那壹抹淺笑 提交于 2019-12-02 15:51:18
Is it possible to create an attribute for a class that is an array? I tried reading this but I didn't get much out of it. I want to do something like this: class CreateArches < ActiveRecord::Migration def change create_table :arches do |t| t.string :name t.array :thearray t.timestamps end end end such that when I call .thearray on an instance of Arch I get an array that I can add new elements to. ruby-1.9.2-p290 :006 > arc = Arch.new ruby-1.9.2-p290 :007 > arc.thearray => [] Create a model with a text field > rails g model Arches thearray:text invoke active_record create db/migrate

Adding New Admins to Active Admin

自古美人都是妖i 提交于 2019-12-02 15:45:39
I am using devise for my users. I recently installed the rails Active Admin gem , everything is working beautifully. However I can't figure out how to add a new admin users. I can see that active admin created an admin_user table in the db with a user admin@example.com, which I use to log in to the interface. I tried adding admin_user as a resource so that I can just click the Add Admin User button within the active admin interface to add a new user, however that does not seem to work. Scott What brian said works perfectly http://net.tutsplus.com/tutorials/ruby/create-beautiful-administration