finding translation keys in Rails - ruby-on-rails-3

I am starting on translating my app and I've read the Rails I18n tutorial, but I don't understand how to refer to a certain key when organizing the locale files in folders
I have this file under /locales/layout/en.yml
en:
header:
search: "Search"
I've tried to refer it with
t( :search)
t( 'header.search')
t( 'header_search')
but it keeps telling me the key is missing
How would I write the key so it would refer the the proper translation key when under the layout folder in locales?

solved..
I had an error in the load files
the correct line is
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]

Related

haml using variable in rails layout for meta keywords

We would like to adjust the meta keywords of a web page based upon the specific action. As a novice at haml, is there a way that this could be done via a provides statement. For example:
in client.html.haml
- provide(:keywords, 'here are unique keywords')
and in our application.html.haml, how would we do this? Like:
%meta{ name: "keywords", content: #{yield(:keywords)} ||= default keywords
but this doesn't work.
You don't say why your approach doesn't work, so I'm going to guess it's a syntax error in your haml (missing closing bracket). Also, I'm not sure what default keywords is or why you're using the ||= operator - either of those may also be causing your solution to "not work".
Something like the following will work as expected:
# application.html.haml
%meta{ name: "keywords", |
content: content_for?(:keywords) ? yield(:keywords) : "default" }
# this could also be achieved using content_for?(:keywords) || "default"
# client.html.haml
- provide :keywords do
this should work

Generating routes with polymorphic_url in rails3

I've got some problems with generating routes with polymorphic_url
Here is a part of my route.rb file :
scope path: '/my-account', controller: 'customers/base', as: :customer do
...
resources :addresses, path: 'my-addresses'
...
end
rakes routes | grep addresses give me exactly the route i want :
customer_addresses GET /:locale/my-account/my-addresses(.:format)
Now, if i use
send('customer_addresses_path)
in a link_to, all work fine.
But if i'm not able to generate the same url with polymorphic url :
app.polymorphic_path([:customer,:addresses])
#ActionController::RoutingError: No route matches {:controller=>"addresses"}
app.polymorphic_path([Customer,:addresses])
#"/Customer/my-account/my-addresses" Not the same url :'(
app.polymorphic_path([Customer.first,:addresses])
#"/1/my-account/my-addresses" Not the same url :'(
Is there a way to use polymorphic_url to generate my url?
Asking a question is a good way to reflect on it.
Solution here:
app.polymorphic_path([:customer,:addresses], locale: :en)

Where did my filename extension go in the parameter list

I am following this answer while trying to figure out how to display images located in my app directory Rails 3, displaying jpg images from the local file system above RAILS_ROOT
I've created a controller as shown there, added the match line to routes.rb, and in a test webpage I want to load up an image called test.jpg using the code
<img src="/serve_image/test.jpg" />
But I get an error saying the file <...>/public/images/test was not found.
Then I went and renamed my image so that the .jpg was gone, and then the script found my image and loaded it up as wanted.
Any ideas where the extension went? I am not sure how to debug this issue.
By default, Rails doesn't match dots in a dynamic segment. So for this route:
match '/serve_image/:filename' => 'images#serve'
:filename will only match up to the first dot it finds. So /serve_image/test.jpg will match test as the filename and will think you're expecting a JPG as a response. What you need to do is tell the router that you want to include the dot in the filename, something like this:
match '/serve_image/:filename' => 'images#serve', :constraints => {:filename => /[^\/]+/}
That will match anything except a forward slash, giving you your complete filename in params[:filename]
See the Rails Routing guide section on Dynamic Segments for more info.

Cannot understand Apache Stanbol enhancer response (Semantic Web)

I am new to semantic web and trying to understand. I am using Apache Stanbol
I am seding text to enhance using Restful service and getting a Structure like
ID: enhancement-e7a7f095-d127-0b6f-16db-b89d181c8314
confidence: 0.9877373098687467
created: 2012-03-19T17:01:03.879Z
creator: org.apache.stanbol.enhancer.engines.opennlp.impl.NEREngineCore
end: 1458
extracted-from: content-item-sha1-18a53d775839d36bf1cc220b3a3fa813a6a64593
relation: enhancement-92681e65-f8c8-fb90-aed2-de05f7898ab9
selected-text: Cologne
start: 1451
type: Place,TextAnnotation,Enhancement
What I wanted to ask is what does start, end means? and relation contains a comma seprated list of IDs. How may I access the related IDs using SPARQL
start: The start character position within the plain text version of the parsed content. Note that the plain text version can be
retrieved by using the multi-part content item support of the Stanbol
Enhancer RESTful API.
end: The end character position. This MUST only be present of "fise:start" is also defined.
relation: Specifies that the current fise:Enhancement has a relation to an other fise:Enhancement. Values need to be resources of the "rdf:type" "fise:Enhancement".
from Apache Stanbol online documentation.

Systematic way to upgrade from attachment_fu to carrierwave?

I'm working on upgrading an app to Rails 3, and attachment_fu is broken so I'm moving to carrierwave. Is there a systematic process that I can go through to upgrade from attachment_fu to carrierwave? Or a tutorial for it? Right now, I'm more interested in getting everything on the database end right. I'm using the filesystem store option for attachment_fu and carrierwave.
I've found a module, UploaderFu from http://ruby.simapse.com/2011/03/migrate-attachmentfu-to-carrierwave.html that tells carrierwave to use the same directories and filenames as attachment_fu. But it's not the entire answer, just part of it.
For example, in the db, I have a UserImage model, with :filename, :content_type, :size, :width, :height, and :user_id attributes. I added a :user_avatar column, and the following to my model
attr_accessible :user_avatar
mount_uploader :user_avatar, UserAvatarUploader
What exactly gets stored in :user_avatar. Is it just the filename? or something else? Do I just need to write a migration to move the data in :filename (stored like "hello_world.png") to :user_avatar? If that's the case I should just use the original :filename instead of creating a :user_avatar column, right?
The column you mount the uploader on is supposed to store an "identifier" for the uploaded file. By default it's just the filename, but you can override it to be almost anything apart from the ID of the record (because you can't know what that is until after saving).
To override: in your uploader class, add this definition :
def identifier
# This is what gets put in the database column!
model.created_on
end
In this example I've used the created_on attribute from the model. If you want to create your own storage mechanism then you need to be able to uniquely identify files by this identifier so be careful what you choose.
I would suggest renaming the column so it describes the file that's being uploaded (like in the carrierwave example). Then you can always change the identifier from filename to something else later.