refinerycms engine i18n route error - ruby-on-rails

need to have multiple language.
configured i18n.rb:
Refinery::I18n.configure do |config|
config.enabled = true
config.default_locale = :en
config.current_locale = :en
config.default_frontend_locale = :en
config.frontend_locales = [:en, :ru]
config.locales = {:en=>"English", :ru=>"Russian"}
end
generated engine in refinerycms:
rails generate refinery:engine product title:string description:text image:image --i18n title description
rails generate refinery:products
I'm getting the following error: No route matches {:locale=>:en, :controller=>"refinery/products/products", :action=>"show", :id=>"1"} when I try to open any page of engine
Please help!

After I added a custom engine to my CMS, I was having the same issue; my 'locale selector' in my application layout file caused the error you described:
-# Haml:
%ul.locales
- locales.each do |locale|
%li= link_to Refinery::I18n.locales[locale], url_for(:locale => locale), :title => Refinery::I18n.locales[locale], :class => "flags-#{locale}"
By changing url_for into refinery.url_for this solved the problem:
-# Haml:
%ul.locales
- locales.each do |locale|
%li= link_to Refinery::I18n.locales[locale], refinery.url_for(:locale => locale), :title => Refinery::I18n.locales[locale], :class => "flags-#{locale}"
Can't explain what happened yet, but maybe this will solve your problem.
To be honest, all credits should go to this answer :)

Did you run:
rake db:migrate
rake db:seed
after you did rails generate refinery:products?

Related

Middleman i18n not working

I'm newbie using ruby and middleman, I've created my project and all are working fine, but when I go to /es path I don't get any translation. I've searched for info without any results and tried to move code between folders testing configs and nothing.
My folder structure is:
|locales
|---en.yml
|---es.yml
|source
|es
|---index.html.haml
|layouts
|---layout.html.haml
|partials
|_header.html.haml
|_navigation.html.haml
|---index.html.haml
My YAML files
en.yml
en:
home: 'Home'
es.yml
es:
home: 'Inicio'
My HAML
%nav
= link_to t(:home), '/', class: "#{'active' if current_page.url == '/'}"
= link_to 'Portfolio', '/portfolio', class: "#{'active' if current_page.url == '/portfolio/'}"
= link_to t(:skills), '/skills', class: "#{'active' if current_page.url == '/skills/'}"
= link_to t(:about), '/about', class: "#{'active' if current_page.url == '/about/'}"
= link_to t(:contact), '/contact', class: "#{'active' if current_page.url == '/contact/'}"
My config
config.rb
###
# Page options, layouts, aliases and proxies
###
# Per-page layout changes:
#
# With no layout
page '/*.xml', layout: false
page '/*.json', layout: false
page '/*.txt', layout: false
# With alternative layout
# page "/path/to/file.html", layout: :otherlayout
# Proxy pages (http://middlemanapp.com/basics/dynamic-pages/)
# proxy "/this-page-has-no-template.html", "/template-file.html", locals: {
# which_fake_page: "Rendering a fake page with a local variable" }
# General configuration
set :partials_dir, 'partials'
activate :i18n, :templates_dir => 'partials'
activate :directory_indexes
# Reload the browser automatically whenever files change
configure :development do
activate :livereload
end
###
# Helpers
###
# Methods defined in the helpers block are available in templates
# helpers do
# def some_helper
# "Helping"
# end
# end
# Build-specific configuration
configure :build do
# Minify CSS on build
activate :minify_css
# Minify Javascript on build
activate :minify_javascript
end
I couldn't write a comment, but I think this might be the reason, your es.yml is wrong, since it starts en:
en:
home: 'Inicio'
Shouldn't it be
es:
home: 'Inicio'
I know this question is months old but I just had the same problem, looked all over the web for hours trying to find and answer and managed to fix the issue by adding these parameters after activating i18n:
config.rb
configure :build do
activate :i18n,
:mount_at_root => 'en',
:lang_map => { :'en' => 'en', :'es' => 'es' },
:path => '/'
end
Obviously, if you want "es" to be your default, change mount_at_root.
Hope this helps.
I achieved localized paths with separate URLs for English and Spanish by
adding index.es.html.erb in the root of the source directory
and setting activate :i18n, :path => "/:locale/" in the config.rb
In the browser, my language selector sends users to / or /es:
English
http://website.com/
Spanish
http://website.com/es
Folder structure
|data
|---home.json
|locales
|---en.yml
|---es.yml
|source
|---index.html.erb
|---index.es.html.erb
|---_slide.erb
|---config.rb
config.rb
configure :build do
activate :i18n, :path => "/:locale/"
activate :directory_indexes
...
end
slide.erb
Using t as a shortcut for I18n.t, I dynamically reference the translated value through the data.
<%= link_to t([data.link.text]),
data.link.href,
:id => data.link.id,
:class => 'btn btn-primary btn-lg btn-dark'
%>
home.json
The value of "text" correlates to the key in the .yml files.
{
"slides": [
{
"text": "slides.learnMore",
...
},
...
]
}
en.yml
en:
slides:
learnMore: "LEARN MORE"
...
es.yml
es:
slides:
learnMore: "APRENDE MÁS"
...
Move all your .erb.html that require to be duplicated per language to the folder: /source/localizable as explained in the docs:
https://middlemanapp.com/advanced/localization/#localizable-templates
You can change this folder name using the modifier: templates_dir:
# Look in `source/language_specific` instead
activate :i18n, :templates_dir => "language_specific"

rails form action missing route

Ruby 1.9.3 and using HAML.
Trying to build a form to go to a specific action, but having problem with routing. The code on the form is
%form#feedback_form{:action=>"give_feedback_account_path", :method => 'post', :style => "padding: 0 5px;"}
%input{:name => "authenticity_token", :value => form_authenticity_token, :type => "hidden"}
blah blah blah
.field
%input#feedback_submit{:type => "submit", :value => "give feedback"}
When I try to submit the form I get a 404 response, and looking at the server log gives me...
Started POST "/give_feedback_account_path" for 127.0.0.1 at 2014-06-03 10:07:12 +0100
ActionController::RoutingError (No route matches "/give_feedback_account_path"):
When I run rake routes to get the details I get
give_feedback_account POST /account/give_feedback(.:format)
{:action=>"give_feedback", :controller=>"accounts"}
What am I missing?
Your url is /give_feedback_account_path, which is not good. To fix it, you can use form_tag helper:
= form_tag give_feedback_account_path, method: 'post', style: 'padding: 0 5px;' do
// your form goes here
change this
:action=>"give_feedback_account_path"
to this
:action => give_feedback_account_path
give_feedback_account_path is a method. You want to call it, to get the actual path.

Spree deface override tutorial

I am following the Spree deface overrides developer guide: http://guides.spreecommerce.com/developer/deface_overrides_tutorial.html
My code matches their's exactly, but I keep getting this error. I looked all around but I didn't see anyone else having this problem or anything similar at all:
undefined method `content_tag' for Spree:Module
I am running Rails 4.0.2 and ruby 1.9.3 (it's possible that the tutorial wasn't updated for rails 4?)
here's my code:
app/overrides/add_sale_price_to_product_edit.rb
Deface::Override.new(:virtual_path => 'spree/admin/products/_form',
:name => 'add_sale_price_to_product_edit',
:insert_after => "erb[loud]:contains('text_field :price')",
:text => "
<%= f.field_container :sale_price do %>
<%= f.label :sale_price, raw(Spree.t(:sale_price)) %><span>*</span>
<%= f.text_field :sale_price, :value =>
number_to_currency(#product.sale_price, :unit => '') %>
<%= f.error_message_on :sale_price %>
<% end %>
")
app/models/spree/product_decorator.rb
module Spree
Product.class_eval do
delegate_belongs_to :master, :sale_price
end
end
You're getting the error because the translation for Spree.t(:sale_price) is not specified. This is failing because Rails 4.0.2 made some changes to the I18n API . You have a few choices.
Add a translation for the missing tag and remember that this content_tag issue is caused by this crazy bug.
Downgrade to Rails 4.0.0 (not recommended)
Upgrade spree to the 2-1-stable branch (or wait until 2.1.4 is released)
Apply this change to your local Spree installation. It should correct this issue.
Any of those should get you working again.

Rails: Capybara doesn't find a div element

I'm using Capybara with RSpec to check my Rails project.
I'm testing errors when form fields are not correctly filled. Here is the form (using haml):
= form_tag '/objects', :class => 'objects-form' do
%ul
%li= select_tag 'object', options_for_select([['Select an object', ''], ['Car', 'CAR'], ['Keys', 'KEYS'], ['Ambrella', 'AMBRELLA']]), :id => 'select-object'
%li= text_field_tag :quantity, nil
%li= submit_tag 'Buy', :id => 'object-submit'
When an error occurs (in this case, not choosing an object but only a quantity), a flash message is displayed (with a .flash-error class name):
- flash.each do |type, msg|
= content_tag :div, msg, :class => "flash-#{type}", :id => 'flash-msg'
So, here is my Capybara test:
it 'Should return error when no object selected' do
within 'form.objects-form' do
fill_in 'quantity', :with => '1'
click_button 'object-submit'
current_path.should == objects_path
save_and_open_page
page.should have_css 'div.flash-error'
end
end
But I get the following Capybara error:
Failure/Error: page.should have_css 'div.flash-error'
expected #has_css?("div.flash-error") to return true, got false
The opened page (using save_and_open_page) shows the error message with the appropriate div:
div#flash-msg.flash-error
I'm using the latest version of Capybara (since many similar problems on Stackoverflow are relative to old versions of Capybara) using gem 'capybara', :git => 'https://github.com/jnicklas/capybara.git'
Any idea? Thank in advance.
EDIT:
Corrected typing mistake on Capybara code, as detected by Alex.
The problem is your selector you are using in capybara is div#flash-error but your div is div#flash-msg.flash-error or more simply div.flash-error.

How to implement badgeville in ruby on rails

Can anyone tell me how to implement badgeville in ruby on rails?
EDIT:
how can I apply this on ruby on rails?
https://github.com/badgeville/badgeville-ruby
I'm not sure how this particular gem work, but normally it should work with following steps
create a file called 'badgeville.rb' inside app/config/initializers
add the following code to badgeville.rb
BadgevilleBerlin::Config.conf(
:host_name => "http://example.com",
:api_key => MY_API_KEY)
restart
then you should be able to use the following commands inside your
controllers/ models
Ex:
new_site = BadgevilleBerlin::Site.new(
:name => "My Website",
:url => "mydomain.com",
:network_id => MY_NETWORK_ID )
success = new_site.save

Resources