ruby-on-rails-3

How could/should I state colon (punctuation) in a YAML file?

旧城冷巷雨未停 提交于 2020-01-14 06:55:10
问题 I am using Ruby on Rails 3.1.0 and I would like to know how to correctly state colon (punctuation) in a YAML file . I tried to support that by adding the following code in my config/locales/defaults/en.yml file en # ':' is the HTML code for ':' test_key_html: Test value: and in my view file I used t('test_key_html') but it doesn't work (in the front end content is displayed the "plain" Test value: text). Is it possible? If so how? 回答1: You should be able to double quote the value: test_key

Rails form to edit JSON object as text

你。 提交于 2020-01-14 06:25:11
问题 I'd like to make a form that lets a user edit one field of a mongoid object as rendered JSON text. There's a field in the model that my rails app should not understand, but I want to expose a generic editor. So for this field, I'd like to render it as pretty JSON, and expose it in a big <textarea> and then parse the JSON back in after any edits. I can think of a dozen ways to do this, but I'm wonder what would be most consistent with Rails philosophy and least divergent from normal

Hw do i render a partial in rails 3.0 using ajax, on radio button select?

爷,独闯天下 提交于 2020-01-14 06:01:10
问题 I try a bit of ajax first time but did not get success, i want to render a partial on radio button select using ajax, here is my code : My script.js: $(document).ready(function(){ $.ajax({ url : "/income_vouchers/income_voucher_partial?$('form input[type=radio]:checked').val()="+$('form input[type=radio]:checked').val(), type: "GET", data: { type: $('form input[type=radio]:checked').val() } }); }); income_voucher.js.erb $("#payment_mode").append(' <% if params[:type]== 'cheque' %> <%= escape

Render static files in /doc in Rails

China☆狼群 提交于 2020-01-14 05:55:46
问题 So far I have in config/routes.rb : match 'doc/:path' => 'doc#show' And in app/controllers/doc_controller.rb : class DocController < ApplicationController layout false def show render File.join( RAILS_ROOT, 'doc', params[:path] ) end end This works find for index.html and other .html files. But it doesn't serve up .css and .js files. It also doesn't serve nested files and directories such as /doc/metrics/output/index.html How can I get Rails to serve up all static files in /doc but without

Migration to create default value

非 Y 不嫁゛ 提交于 2020-01-14 05:50:09
问题 So I want to know whether we can write a new migration just to set default value of a field,which is already created. I know how to write edit the old migration and set its default value. I want to do this because I have done so many migrations and I cant roll back now and edit that file. And also, Is there any way to rollback to a particular migration? Thanks in advance 回答1: Run rails g migration add_default_value_to_table then in the migration file def up change_column :table_name, :column

Chained select box in Rails 3

ε祈祈猫儿з 提交于 2020-01-14 05:49:21
问题 I have a table related with itself: id | data | owner_id 1 | A | null 2 | B | 1 3 | C | 1 4 | D | 2 So therefore B and C belong to A and D belongs to B. My question is how can I display in a Rails 3 view a chained select box where if you select a "data" then another select box appears with its "children" and when you select one of the children another select box appears with its children and so forth using Ajax? For example in the previous table if I select A in the select box another select

Ruby on Rails - sqlite 3 rake migrations not updating the database

↘锁芯ラ 提交于 2020-01-14 05:26:40
问题 I am using RoR (3.2.2) and SQLite 3 (1.3.5). When I initially generate a model I am able to successfully create a database. However, whenever I try to use the migration generator it appears to not have any issues in the command line (no errors), but when I check the database nothing has updated or changed. For example, I create this database: $ rails generate model User name:string email:string db/migrate/[timestamp]_create_users.rb class CreateUsers < ActiveRecord::Migration def change

Paperclip, how to append a random stamp at the end of the file?

限于喜欢 提交于 2020-01-14 04:35:08
问题 I'm using paperclip with my rails 3 app. I want to append a random string, nothing to long or crazy at the end of the file to cache bust the CDN. Anyone know a real simple way to do this? Here is what I have currently: has_attached_file :photo, :styles => { :thumb => "70x70>" }, :storage => :s3, :s3_credentials => "#{Rails.root}/config/s3.yml", :path => "/:rails_env/public/users/:id/:style/:basename.:extension", ..... I would like a file name like FILENAME_31313.png Where 31313 is random

How to dynamically generate association names?

时光毁灭记忆、已成空白 提交于 2020-01-14 04:25:08
问题 I am using Ruby on Rails 3.2.2 and the Squeel gem. I have following statements and I am trying to refactoring the my_squeel_query method in a Mixin module (since it is used by many of my models): # Note: 'article_comment_associations' and 'model_as_like_article_comment_associations' # refer to database table names. class Article < ActiveRecord::Base def my_squeel_query commenters. .where{ article_comment_associations.article_id.eq(my{self.id}) & ... } end end class ModelAsLikeArticle <

Rails commands only work on one terminal

自闭症网瘾萝莉.ら 提交于 2020-01-14 04:04:09
问题 I installed Ruby and then RVM, and then configured Rails. It all works when I call it from the original terminal. But when I try to call various commands from new terminals, the system just gives an error message such as this one: $rails server The program 'rails' is currently not installed. You can install it by typing: sudo apt-get install rails Why does that happen? Is there some global variable which needs to be set? I am using Ubuntu by the way. 回答1: Example of how/where gems are