Rails

Styling form error message - bootstrap/rails

匿名 (未验证) 提交于 2019-12-03 02:45:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: The error messages for my rails form looks like shit with bootstrap. Does anyone know a solution for better (nice looking) error messages? I use Rails and Bootstrap. My form (it's a helper) is like this: <%= form_for(@user) do |f| %> <% if @user.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2> <ul> <% @user.errors.full_messages.each do |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %> <div class="form-inline"> <%= f.text_field :email, class:

Getting the rails &#039;params&#039; without the defaults?

匿名 (未验证) 提交于 2019-12-03 02:45:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is there a neat way in rails to get a hash of the params without the default ones of 'action' and 'controller'? Essentially without any param that wasn't added by me. I've settled for: parm = params.clone parm.delete('action') parm.delete('controller'); But wondering if there is a neater way to do this? 回答1: You could use except: params.except(:action, :controller) http://as.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Hash/Except.html 回答2: If you are working in a controller, you should also have access to the request object. To make

rails install pg - Can&#039;t find the &#039;libpq-fe.h header

匿名 (未验证) 提交于 2019-12-03 02:45:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: $ sudo bundle install Result Fetching gem metadata from https://rubygems.org/........... Fetching gem metadata from https://rubygems.org/.. Using rake (0.9.2.2) Using i18n (0.6.1) Using multi_json (1.3.6) Using activesupport (3.2.8) Using builder (3.0.4) Using activemodel (3.2.8) Using erubis (2.7.0) Using journey (1.0.4) Using rack (1.4.1) Using rack-cache (1.2) Using rack-test (0.6.2) Using hike (1.2.1) Using tilt (1.3.3) Using sprockets (2.1.3) Using actionpack (3.2.8) Using mime-types (1.19) Using polyglot (0.3.3) Using treetop (1.4.11)

How to respond_to PNG or JPG in Rails and generate image from HTML?

匿名 (未验证) 提交于 2019-12-03 02:45:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am looking for a gem or solution to generate image in controller response. It would be nice if it's possible to do in controller like that: respond_to :html, :png def show ... respond_to do |format| format.html format.png { ??? } # some html to png converter end end When the png format is requested the response handles with template: #show.png.haml %h1 Some title %p Some content The result should be an image. I know about pdf generation solutions PDFKit , prawn and am looking for image generation. Does anybody know working solution/example

Why does Rails 3 with Mysql2 Gem ActiveRecord::Base.connection.execute(sql) return Array not Hash?

匿名 (未验证) 提交于 2019-12-03 02:45:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm in the process of upgrading an application to Rails 3. I've decided to go with the mysql2 gem. There's some legacy code in the app that makes calls like: results = ActiveRecord::Base.connection.execute(sql) In the 2.3.x version, it used results.each_hash do |row| ... But with gem mysql2, results is type Mysql2::Result , which has only an each method. Checked the docs and they specify results should be a hash keyed on field name. Great! But in fact, it is an Array , not a Hash . When I use the rails console and instantiate my own Mysql2:

How to stop (and restart) the Rails Server?

匿名 (未验证) 提交于 2019-12-03 02:45:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm following the instructions here http://railsinstaller.org/mac to get up and running with Rails on a Mac running OS X 10.8.2 At step 8 I'm asked to restart Rails server but how? I'm assuming via a command line, but from within the already open ruby terminal window or a new one? 回答1: Press Ctrl+C When you start the server it mentions this in the startup text. 回答2: On OSX, you can take advantage of the UNIX-like command line - here's what I keep handy in my .bashrc to enable me to more easily restart a server that's running in background (

How do I find the source file for a rake task?

匿名 (未验证) 提交于 2019-12-03 02:45:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 选择语言 中文(简体) 日语 英语 中文(繁体) 由 翻译 强力驱动 问题: I know you can view all possible rake tasks by typing rake - T But I need to know what exactly a task does. From the output, how can I find a source file that actually has the task? For example, I'm trying to find the source for the db:schema:dump task. 回答1: Despite what others have said, you can programmatically get the source location of rake tasks in a rails application. To do this, just run something like the following in your code or from a console: # load all the tasks associated with the rails app

Rails 3 Observer ― looking to learn how to implement an Observer for multiple models

匿名 (未验证) 提交于 2019-12-03 02:45:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'd like to add an Auditor Observer which does an action anytime after_create for 3 models (books, characters, authors)... I recently heard of the Observer capability but can't find any documentation on the ability. Is it support in Rails 3? How do I create an Auditor Observer that does something after_create for 3 models? Thanks 回答1: Rails observers are sweet, You can observe multiple models within a single observer First, you need to generate your observer: rails g observer Auditor Then, in your fresh auditor_observer.rb file define the

Source maps in Ruby on Rails through sprockets

匿名 (未验证) 提交于 2019-12-03 02:45:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'd like to add source map support on a rails 3.2 application I am working on. As far as I know, generating source maps is not supported by Sprockets and from its github page it looks like the feature is planned for 4.0. I am working with Sprockets 2.2 and I think monkey patching is the only way to go. The module Processing under the main Sprockets module gives access to the js_compressor function which can be patched to generate source map for a single file. But, I don't know how to add this when the JS files combine. I am using Uglifier 2

rails collection_select vs. select

匿名 (未验证) 提交于 2019-12-03 02:45:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: collection_select and select Rails helpers: Which one should I use? I can't see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a scenario where collection_select is better than select ? or is anything I am missing here? 回答1: collection_select is intended to be used when the list of items is an array of ActiveRecord objects. collection_select is built on the top of select so it's a convenient method when you need to display a collection of objects and not an array of strings.