ruby-on-rails-3.1

I18n: What is the difference between using 't(:test_key)', 't('test_key')' and 't('.test_key')'?

半世苍凉 提交于 2019-12-21 21:38:48
问题 I am using Ruby on Rails 3.1 and I would like to know how , when and why I should use one of the following code rather than another on internationalizing my application (I18n gem): t(:test_key) t('test_key') t('.test_key') That is, what is the "subtle" difference between using t(:test_key) , t('test_key') and t('.test_key') ? What are best practices about this issue? 回答1: I think first two are equivalent and you just refer to main key in your translations, fo example t('hello_world') # t(

openssl smime in ruby/rails

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-21 20:58:14
问题 So, i have this application that creates a zip file with images and stuff and i want to sign it using smime . if i use the terminal command: openssl smime -binary -sign -passin "pass:MYPASS" -signer ./MyCertificate.pem -inkey ./MyKey.pem -in ./manifest.in -out ./signature.out -outform DER Formated: openssl smime -binary -sign -passin "pass:MYPASS" \ -signer ./MyCertificate.pem -inkey ./MyKey.pem \ -in ./manifest.in -out ./signature.out -outform DER the manifest.in is the file witch contains

Rails 3.1 Having iframe in view makes layout stop rendering

喜夏-厌秋 提交于 2019-12-21 19:24:10
问题 So I have a basic layout file: <!DOCTYPE html> <html dir="ltr" lang="en-US"> <head> <%= stylesheet_link_tag "logged_out" %> <%= javascript_include_tag "application" %> <%= stylesheet_link_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/ui-lightness/jquery-ui.css" %> </head> <body> <!-- header stuff here --> <%= yield %> <!-- footer stuff here --> </body> </html> And with any normal html its fine. However if I add in an iframe like this to a view: <iframe id="form" height="480

Why does a single record lookup return an array? (Rails beginner)

我的梦境 提交于 2019-12-21 17:13:06
问题 I have a where operation on a model that returns a single object. But I can't seem to use it in object notation (it appears to return an array with the object at [0]). store = Store.where("some_id = ?", some_id) puts store.name # doesn't work puts store # shows array with the object at [0] 回答1: Because sometimes you don't know how many objects a query should return, so for consistency you always get an array. To get a single object use store = Store.where("some_id = ?", some_id).first If you

Why Active Record relation is not returned in console?

爱⌒轻易说出口 提交于 2019-12-21 12:58:47
问题 I have finally started upgrading my Rails apps from 2.3.8 to 3.1.0. I was watching RailsCasts (http://railscasts.com/episodes/202-active-record-queries-in-rails-3) about Active Record queries. When I open up the console (rails c) and do query similar to this: articles = Article.order("name") Instead of returning Active Record relations, I see the query executed. What am I doing wrong here? Rails version: 3.1.0 RVM on 1.9.2 Thank you for your help! EDIT: I have added a screenshot from the

Is it considered safe to manually edit schema.rb in rails

吃可爱长大的小学妹 提交于 2019-12-21 12:43:30
问题 I came across a problem where I was working on two branches on a rails project and each project has a migration to add a column. At the time, rake db:migrate:reset cause a problem and I solely relied on my schema.rb to correctly represent the state of my database. At one point, I came across a problem where a column added by branch A got into the schema of branch B. Since migrate:reset was not an option, I resorted to manually editing the schema file to. I committed this change that basically

How to enter unique associations only?

▼魔方 西西 提交于 2019-12-21 09:23:24
问题 Running the following code to add an association enters multiple entries each time the code is ran: store.categories << category Is there a way to make it only enter unique associations between the two models in the db? 回答1: Directly from the rails guides, hope it helps: class Person has_many :readings has_many :posts, :through => :readings, :uniq => true end 回答2: Ignoring duplicates only seem to work with begin and rescue logic: begin stores.categories << category rescue puts "Duplicate

How to enter unique associations only?

大憨熊 提交于 2019-12-21 09:23:14
问题 Running the following code to add an association enters multiple entries each time the code is ran: store.categories << category Is there a way to make it only enter unique associations between the two models in the db? 回答1: Directly from the rails guides, hope it helps: class Person has_many :readings has_many :posts, :through => :readings, :uniq => true end 回答2: Ignoring duplicates only seem to work with begin and rescue logic: begin stores.categories << category rescue puts "Duplicate

Trouble on using the i18n gem with partial template files

耗尽温柔 提交于 2019-12-21 08:00:11
问题 I am using Ruby on Rails 3.1 and I would like to know how to correctly handle internationalization related to partial template files. That is, ... ... in my app/views/users/flag.html.erb file I have: <%= t('.test_key1') %> <%= render :partial => "/users/flag_form" %> ... in my app/views/users/_flag_form.html.erb file I have: <%= t('.test_key2') %> If in my config/locales/views/users/en.yml file ( note : I am organizing files as stated in the official RoR guide) I use en: users: flag: test

How can I keep my initializer configuration from being lost in development mode?

时光总嘲笑我的痴心妄想 提交于 2019-12-21 06:57:32
问题 I'm working on a Rails app that uses an engine. I'm using an initializer to configure one of my engine's controllers so that it will trigger an action in the host app. The code looks something like this: # config/initializers/my_engine.rb MyEngine::SomeController.after_filter proc { # Do something in the host app }, :only => :update This works fine in production, but in development mode, the proc is only called on the first request. This is because the classes are getting reloaded and this