Rails

Using Rails serialize to save hash to database

匿名 (未验证) 提交于 2019-12-03 02:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm try to save a hash mapping ids to a number of attempts in my rails app. My migration to the database to accommodate this new column: class AddMultiWrongToUser In my model I have: class User But when I use the rails console to test this by doing: user = User . create () user . multi_wrong = { "test" => "123" } user . save The output is false. What's going wrong here? 回答1: The column type is wrong. You should use Text instead of String. Therefore, your migration should be: def self . up add_column : users , : multi_wrong , : text

What language (i.e. PHP, Ruby on Rails) does Twitter use? [closed]

匿名 (未验证) 提交于 2019-12-03 02:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to build an application that has many points in common with Twitter. So, I was wondering whether there is a language more suitable to create a site like that. I don't want to discuss about what is the best programming language.. I only ask you what language Twitter uses (if anyone know..) Thanks 回答1: Ruby on Rails for the frontend and scala for some of the backend: http://www.artima.com/scalazine/articles/twitter_on_scala.html 回答2: They originally used Ruby on Rails, but it's been considered to be the cause of a lot of their

Rails 3.1 asset pipeline: how to load controller-specific scripts?

匿名 (未验证) 提交于 2019-12-03 02:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: If I generate a new controller in Rails 3.1, also a javascript file with the name of the controller will added automatically. Firstly, I thought this javascript file will used only, when the related controller is called. By default there is the instruction //= require_tree . in the application.js -file, that include every javascript file on it's tree. How could I load only the controller specific script? 回答1: To load only the necessary name_of_the_js_file.js file: remove the //=require_tree from application.js keep your js file (that you

No route matches “/users/sign_out” devise rails 3

匿名 (未验证) 提交于 2019-12-03 02:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've installed devise on my app and applied the following in my application.html.erb file: Signed in as . This cannot be cheese? or I ran rake routes and confirmed that all the routes are valid. Also, in my routes.rb file I have devise_for :users and root :to => "home#index" . I get the following routing error when clicking the "Sign out" link: No route matches "/users/sign_out" Any ideas what's causing the error? 回答1: I think the route for signing out is a DELETE method. This means that your sign out link needs to look like this: :delete %>

How can I avoid running ActiveRecord callbacks?

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have some models that have after_save callbacks. Usually that's fine, but in some situations, like when creating development data, I want to save the models without having the callbacks run. Is there a simple way to do that? Something akin to... Person#save( :run_callbacks => false ) or Person#save_without_callbacks I looked in the Rails docs and didn't find anything. However in my experience the Rails docs don't always tell the whole story. UPDATE I found a blog post that explains how you can remove callbacks from a model like this: Foo

Rails server does not start by command “Rails s”

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm new to ruby and rails and i installed rails in to the ubuntu. but when i go to the start server by typing "rails s" it doesn't start and comes following message . but i can create a new project by command rails new new_project. please rails specialists help-out me. root@ubuntu:~# rails s Usage: rails new APP_PATH [options] Options: -j, [--javascript=JAVASCRIPT] # Preconfigure for selected JavaScript library # Default: jquery -m, [--template=TEMPLATE] # Path to an application template (can be a filesystem path or URL) [--dev] # Setup the

ActiveRecord::AdapterNotSpecified database configuration does not specify adapter

匿名 (未验证) 提交于 2019-12-03 02:02:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: When I use heroku open my web app works fine but when I'm using rails s (localhost) I am running into this error: ActiveRecord::AdapterNotSpecified database configuration does not specify adapter Why is this? This is my database.yml # PostgreSQL. Versions 8.2 and up are supported. # # Install the pg driver: # gem install pg # On OS X with Homebrew: # gem install pg -- --with-pg-config=/usr/local/bin/pg_config # On OS X with MacPorts: # gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config # On Windows: # gem install pg

Ruby on Rails 4 select multiple

匿名 (未验证) 提交于 2019-12-03 02:00:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a form that creates new users. I am trying to add a drop down option to select permission levels. I want to be able to select multiple permission levels per user. This is my view, I added {:multiple => true} : true}, class: "input-lg" %> My controller, I added :permission => [] : def user_params params.require(:user).permit(:name, :email, :password, :password_confirmation, :admin, :permission => []) end The error I get for my view, f.select: wrong number of arguments (5 for 2..4) How do you make a select multiple for Rails 4? 回答1:

In Ruby on Rails, to extend the String class, where should the code be put in?

匿名 (未验证) 提交于 2019-12-03 02:00:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: If on Ruby on Rails, I need to add a method called class String def capitalize_first # ... end end and wonder where should the file go to? (which directory and filename, and is any initialize code needed?) This is for a Rails 3.0.6 project. 回答1: I always add a core_ext directory in my lib dir. Create and initializer for loading the custom extensions (for example: config/initializers/core_exts.rb ). And add the following line in it: Dir[File.join(Rails.root, "lib", "core_ext", "*.rb")].each {|l| require l } and have your extension like: lib

How can I enable Source Maps for Sass in rails 4?

匿名 (未验证) 提交于 2019-12-03 02:00:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: According to this issue https://github.com/rails/sass-rails/pull/192 sass-rails hasn't support for Sass 3.3 yet. But it seems that sass-rails-source-maps has been depending on Sass 3.3 since the very beginning. So is there a way to use this gem with sass-rails ? According to the readme with sass-rails-source-maps , Chrome dropped support of the Source Maps files from Sass older than version 3.3. Does that mean there is no way of using Sass Source Maps with Chrome devtools now? 回答1: There is a great new drop in replacement for sass-rails,