Rails

change column name Rails

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have this table: class CreateShoes < ActiveRecord::Migration def change create_table :shoes do |t| t.string :name t.boolean :leather t.integer :season t.timestamps null: false end end end the 'season' column should be called 'season_id'. I know that I have to write 't.rename :season, :season_id' as explained in http://edgeguides.rubyonrails.org/active_record_migrations.html#column-modifiers but I don't manage to find the right syntax. Should it be? class CreateShoes < ActiveRecord::Migration def change create_table :shoes do |t| t.string

How to enable CORS in Rails 4 App

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm just about to pull my hair out... I've been trying to enable CORS in this Rails app since the morning and it just doesn't work. I've tried this , using Rack Cors Gem , this answer and this post all without success. Can someone point me in the right direction? Here's my js: var req = new XMLHttpRequest(); if ('withCredentials' in req) { // req.open('GET', "https://api.github.com/users/mralexgray/repos", true); req.open('GET', "http://www.postcoder.lc/postcodes/" + value, true); // Just like regular ol' XHR req.onreadystatechange =

Rails 5: Array values in the parameter to `Gem.paths=` are deprecated

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Building websockets app based off of actioncable-examples. When starting server, running rake, etc. I keep getting the message: Array values in the parameter to `Gem.paths=` are deprecated. Haven't seen a solution here, but did find one. I wanted to post the question and answer here so that it's available. 回答1: I found the answer in RubyGems issue #1551 here . The binstubs, the files in the bin folder, need to be updated. The best way to do this is: bundle update spring bundle exec spring binstub --remove --all bundle exec spring binstub -

Rails - Using %W

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have the following which works well: def steps %w[hello billing confirmation] end steps.first But I want to do this: def step_title %w['Upload a photo' 'Billing Info' 'Confirmation Screen'] end steps.first How does %w allow for that? I tried a google search but google is weak with these types of characters. Thanks 回答1: %w creates an "array of words," and uses whitespace to separate each value. Since you want to separate on another value (in this case, whitespace outside sets of quotation marks), just use a standard array: ['Upload a photo'

For Rails, how to access or print out config variables (as experiment or test / debugging)

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: For example, in config/environments/production.rb in a Rails 3 app, there is config . serve_static_assets = false and many variables. How can they be all printed out as a whole (perhaps in an object, instead of specifying each one-by-one) (print out in a view, such as FooController#index), just for looking into what types of values are available and to see what they are set to? Also, how to print out the values in the .yml files (as a hash and/or in some config object?) and in config/initializers , such as for MyAppFoo ::

Rails Migration to make a column null =&gt; true

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I had originally created a table with column as t.string "email", :default => "", :null => false The requirement has changed and now I need to allow email to be null. How can I write a migration to make :null => true 回答1: Try: change_column :table_name, :email, :string, :null => true 回答2: I could not get the above solution to work with Active Record 4.0.8 and Postgresql 9.3 However change_column_null worked perfectly. change_column_null :users, :email, true The reverse has a nice option to update existing records (but not set the default)

Start using Ruby on Rails, Web Services and OAuth

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am running Ruby on Rails 3 and I would like to create an application APP1 that acts as a Web Service . Then create another RoR application APP2 that can communicate (send/get information) with APP1 using the OAuth protocol. What I have to do to start (I am not expert about programming in those topics but I read a lot and I know how they conceptually\theoretically works) ? Is it good to think to implement my custom code or maybe it is better to use plugin or gem? Why? If it is possible, can you write a TODO list and steps to

Devise controllers rails

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using Rails 3, on ruby 1.8.7. And using for auth. devise (1.1.3). But it is a quite large community site i'm building, so i have a table for profiles and a table for users. And every time a user registers it should generate a profile also, but in devise i'm not allowed the controllers, so i'm completely lost.. Edit Now it says undefined method `getlocal' for Tue, 28 Dec 2010 11:18:55 +0000:DateTime Then when i make a file in lib called date_time.rb with this code class DateTime def getlocal "it works" end end And require it in my

Rails 4 - syntax error, unexpected tIDENTIFIER, expecting end-of-input

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a piece of code that I am trying to run with rspec. require 'spec_helper' describe "User" do before { @user = User.new(name: "Example User", email: "user@example.com", password: "foobar", password_confirmation: "foobar") } subject { @user } it { should respond_to(:name)} end I get the following error c:\Sites\sample_app>rspec spec/models/user_spec.rb C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec /core/configuration.rb:819:in `load': c:/Sites/sample_app/spec/models/user_spec. rb:1: syntax error,

Translated attributes in Rails error messages (Rails 2.3.2, I18N)

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have defined translated attributes and model names in the translation file and Modelname.human_attribute_name(...) returns the correctly translated attribute name, but the attribute names in the error messages are untranslated. What is needed that the attribute names in the error messages are translated? 回答1: From the Guide on the subject, you will need to set up the localization file properly with your model names and attribute names: en: activerecord: models: user: Dude attributes: user: login: "Handle" Since this is YAML, make sure all