Rails

Rails - cannot run app: Unable to load the EventMachine C extension;

匿名 (未验证) 提交于 2019-12-03 01:57:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: When I run an app on Lion OS X, I get this error: Unable to load the EventMachine C extension; To use the pure-ruby reactor, require 'em/pure_ruby' /Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/eventmachine-1.0.0/lib/eventmachine.rb:8:in `require': no such file to load -- rubyeventmachine (LoadError) from /Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/eventmachine-1.0.0/lib/eventmachine.rb:8:in ` ' from /Users/adam/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require' from /Users/adam/.rvm/gems/ruby-1.9.2-p290

“uninitialized constant Sass::Script (NameError)”

匿名 (未验证) 提交于 2019-12-03 01:57:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I had first to change my Gemfile from (I deleted the comments to make the text shorter): source 'https://rubygems.org' gem 'rails', '4.2.0' gem 'sqlite3' gem 'sass-rails', '~> 5.0' gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.1.0' gem 'jquery-rails' gem 'turbolinks' gem 'jbuilder', '~> 2.0' gem 'sdoc', '~> 0.4.0', group: :doc group :development, :test do gem 'byebug' gem 'web-console', '~> 2.0' gem 'spring' end to: source 'https://rubygems.org' gem 'rails', '4.2.0' gem 'sass-rails', '5.0.1' gem 'uglifier', '2.5.3' gem 'coffee-rails',

Methods for limiting the Rails render format to html

匿名 (未验证) 提交于 2019-12-03 01:57:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a Rails 2.1.2 site that only has html templates e.g. jobs.html.erb, so when I request a restful resource: www.mysite.com/jobs/1 It renders my job in html, however, if I request: www.mysite.com/jobs/1.xml I get the error: Template is missing Missing template jobs/show.xml.erb in view path c:/workspace/mysite/app/views What's worse is that I can also request something like www.mysite.com/jobs/1.xyz And indeed I see the error: Template is missing Missing template jobs/show.xyz.erb in view path c:/workspace/mysite/app/views To stricly

Rails routes with :name instead of :id url parameters

匿名 (未验证) 提交于 2019-12-03 01:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a controller named 'companies' and rather than the urls for each company being denoted with an :id I'd like to have the url use their :name such as: url/company/microsoft instead of url/company/3 . In my controller I assumed I would have def show @company = Company.find(params[:name]) end Since there won't be any other parameter in the url I was hoping rails would understand that :name referenced the :name column in my Company model. I assume the magic here would be in the route but am stuck at this point. 回答1: params The bottom line

Rails and bootstrap - Add HTML tags to a submit button text

匿名 (未验证) 提交于 2019-12-03 01:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a form for a like/unlike button using ajax : = form_for like, :html => { :method => :delete}, :remote => true do |f| = f.submit pluralize(@video.likes.count, 'like'), :class => "btn btn-warning btn-mini", "data-disable-with"=> "Just a moment..." The form works perfectly. I would like to add an icon in front of the text in the submit button. The haml code for adding the icon is the following (twitter bootstrap) : %i.icon-heart.icon-white Is there a way to add this html to the button? I tried adding it as plain html, but rails rendered

rails 3,Kaminari pagination for an simple Array

匿名 (未验证) 提交于 2019-12-03 01:55:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: For paginating a common array I got this solution, @arr_name = Kaminari.paginate_array(@arr_name).page(params[:page]).per(PER_PAGE_RECORDS) PER_PAGE_RECORDS is a variable with value as per needed for pagination. Any better Ideas?? Also to have an ajax call for using pagination one can use this, In your view, give id to your div tab div id="paginate" and inside it true %> And in js response file put, $('#paginate').html(' true).to_s) %>'); So your requests will be AJAX. Thanks. 回答1: This is the only available helper method to paginate an

Rails model validation on create and update only

匿名 (未验证) 提交于 2019-12-03 01:55:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: If I want to have validation only on create, then I can do validates_presence_of :password, :on => :create But how do I say on create and update? I tried this but it didn't work: validates_presence_of :password, :on => [ :create, :update ] Do I have to define the validation two times? 回答1: By default, the validations run for both create and update. So it should be just: validates_presence_of :password The :on key just allows you to choose one of them. 回答2: Only write: validates_presence_of :password No need... on => :create 回答3: You can use

Uninstalling rails and gems, getting error \"cannot uninstall, check 'gem list -d …'

匿名 (未验证) 提交于 2019-12-03 01:55:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm going to start with the usual noob line, "I'm new to rails". Oh, and I'm running Mac OSX 10.6.4 I've been following a bunch of guides to get set up, specifically these two here and here . The guides are great, the reason I'm using the second one is because of RVM and the reason I'm using the first is for MYSQL. Anyway, when I started, I wasn't following the directions completely and so after I installed RVM, for some reason I installed rails with sudo gem install rails -v 2.3.8 because thats the version I need. So... I realized

Rails: How Does csrf_meta_tag Work?

匿名 (未验证) 提交于 2019-12-03 01:55:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm a PHP developer learning Ruby on Rails by reading Michael Hartl's tutorial . Here is a quote from the book, referring to csrf_meta_tag : ...the Rails method csrf_meta_tag [prevents] cross-site request forgery (CSRF), a type of malicious web attack. Don’t worry about the details (I don’t); just know that Rails is working hard to keep your application secure. The thing is, I'm genuinely curious. How does inserting csrf-param and csrf-token meta tags prevent CSRF? I tried Googling, but couldn't find anything. 回答1: csrf_meta_tag is basically

Rails: How to list database tables/objects using the Rails console?

匿名 (未验证) 提交于 2019-12-03 01:54:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I was wondering if you could list/examine what databases/objects are available to you in the Rails console. I know you can see them using other tools, I am just curious. Thanks. 回答1: You are probably seeking: ActiveRecord::Base.connection.tables and ActiveRecord::Base.connection.table_structure("projects") You should probably wrap them in shorter syntax inside your .irbrc . 回答2: I hope my late answer can be of some help. This will go to rails database console. rails db pretty print your query output .headers on .mode columns (turn headers on