Refinerycms 2.1.0, I18n breaks navigation menu - ruby-on-rails

I have a website powered by refinerycms 2.1.0.
I need to support 4 languages, so I use refinerycms-i18n 2.1.0 gem.
I have all the flags displaying in admin area, different versions of the pages seem to work.
I have my languages menu in header:
link_to "ESP", {:locale => :es}, :class => (params[:locale] == "es" ? 'selected' : nil)
the links are generated like this: mysite.com/es/....
For english locale, though, no :locale parameter in url is set.
The problem is, for all the locales except english one, the links in navigation menu seem to be generated wrong: instead of slug, page id is used. Links look like .../es/<page_id> or .../es/parent_page_slug/<page_id>. And when I click them, 404 is rendered. For english locale everything is fine: .../parent_page_slug/child_page_slug.
I do also have menu in footer, implemented like described here, and it works perfectly with all the locales.
My routes.rb:
get '/' => "application#index"
mount Refinery::Core::Engine, :at => '/'
Since 2.1.0, as far as I understand, I don't even have access to _menu.html.erb file. What are my options? I'd be glad to provide you with more information if needed. Thank you for help!

Regarding the 404 error, it could be that you don't have content for other languages. Or if your are translating the title of page also, you might at least want to write the page title in different languages too.
Refinerycms 2.1.0 provides a different way of generating custom menus which is discussed here

Related

Silex bilingual URLs routing

I want to know what is the best way to implement what want (see below) in Silex.
Here is what I want:
all URLs must start with locale (/en/page1, /fr/page1, /en/page2, /fr/page2, ....)
when the user hits the home page I will check the browser language and add /en or /fr to home page
when adding /en or /fr to home page, is there a way to do that in Silex without redirecting (I think redirecting home page is not a good SEO practice (my knowledge in SEO is very limited so maybe i am wrong))?
Thank you
You can have a look at http://silex.sensiolabs.org/doc/organizing_controllers.html
Especially :
$app->mount('/blog', $blog);
So using this I think you can do something like :
$app->mount('/{_locale}', $site);
I haven't tried it but I think it would work, please let me know :)
To me, this was the simplest and cleanest option for Silex v2.x:
Install the silex-local package
composer require pmaxs/silex-locale "^2.0"
Add the LocalServiceProvidet to your app.php file:
$app->register(new Pmaxs\Silex\Locale\Provider\LocaleServiceProvider(), [
'locale.locales' => ['en', 'ca', 'es'],
'locale.default_locale' => 'en',
'locale.resolve_by_host' => false,
'locale.exclude_routes' => ['^_'],
]);
$app->register(new Silex\Provider\LocaleServiceProvider(), []);
This way, you won't have to add anything extra in your endpoints, plus everything is handled by default.
Look at https://github.com/pmaxs/silex-locale for information with Silex v1.x.

Rails 4: Any way to fix/use regular html href links w/o 'link_to'?

So my question is that I have a link to 'pages/home' and I click on it, ill go to my home page.
But then I'll try to click again, but the link changes to 'pages/pages/home' and then I'll get a routing error. Is there anyway to fix this using regular old anchor tags? or do i need to use link_to?
edit:
This is how i insert my link into the page.
Home
This is not related to rails, the problem is you use a relative url :
Home
This will lead to <any_path_you're_in>/pages/home.
For it to be absolute, you have to use (note the leading slash):
Home
By the way, it's quite a bad practice to use hardcoded url to your own rails app. You can avoid using #link_to while still taking advantage of rails' routing :
Home
Provided you have a "home" route, of course :
get '/pages/home' => 'pages#home', as: 'home'
This will save you a lot of pain when you decide to restructure your app.

Rails 3.1 build GET form that creates a custom URL route that is SEO friendly

I would like to create custom SEO friendly routes similar to what is used by http://realestate.com.au For example the following page is shown by google when the search term "real estate melbourne" is used:
www.realestate.com.au/buy/in-melbourne,+vic+3000/list-1
I would like use the following format. mysite.com/trips/search/melbourne-to-sydney/01-01-2011
I have configured the routes in my routes.rb file to get it to pick up the correct parameters when a url is entered is this format.
routes.rb
match '/trips/search(/:fl(-to-:tl(/:tripdate)))' => 'trips#someaction'
My question is how do I setup a form in rails 3 to send a GET request using the above url structure. I have tried playing around with to_params though it seems to then change all my edit, show links etc which is not intended. I could build the link using javascript though I guess this would be a hacky option and the site would not work if javascript was disabled.
Is there a neat way to be able to create a GET submit form in Rails 3.1? The fields are select lists containing name and ids.
Thanks for your help.
This will help you immensely with the friendly URL portion
http://norman.github.com/friendly_id/file.Guide.html
https://github.com/norman/friendly_id

Can prawn generate PDFs with links?

I need to embed a link into a generated pdf in a ruby on rails app. Is there a way to do this with prawn?
Reading about this it turns out that prawn-format was the answer for awhile, but 0.7.x broke this.
prawn-format uses the link_annotate(rect, options={}) function to create links. What options need to be passed into this to get it to create a link in the PDF?
edit:
I would like to see a code example of this being done if anyone has one.
I know this is an old question, but for those still stumbling upon it, in current versions of Prawn, you can use inline format like this:
pdf.text "Website: <link href='http://www.stackoverflow.com'>stackoverflow</link>", :inline_format => true
If you are attempting to create a link to an external page (http://google.com), for instance you could use the following, to place a link that is 100x100 and placed at 5, 5 from the bottom left of the page, with a 1px border:
pdf.link_annotation([100, 100, 5, 5], :Border => [0,0,1], :A => { :Type => :Action, :S => :URI, :URI => Prawn::LiteralString.new("http://google.com") } )
Prawn Format would parse the text passed to the pdf.text method and find html a tags. It would then use regular expressions to parse out the target and link text and finally create a link like the one above with a bounding box (the first param) that would fit around the text that was within the tags. I'm not sure how you could achieve this without Prawn Format. But that is how you can create a link using link_annotation.
As of Prawn 0.7, prawn-format is
completely unsupported, and will not
work with versions of Prawn 0.7+. Feel
free to fork and fix, of course
- prawn-format's homepage on github
The other option is to use prawn's built in low-level annotation support:
http://prawn.majesticseacreature.com/docs/prawn-core/classes/Prawn/Document/Annotations.html#M000158
Heres the method:
link_annotation(rect, options={})
A convenience method for creating Link
annotations. rect must be an array of
four numbers, describing the bounds of
the annotation. The options hash
should include either :Dest
(describing the target destination,
usually as a string that has been
recorded in the document‘s Dests
tree), or :A (describing an action to
perform on clicking the link), or :PA
(for describing a URL to link to).
I recently did it like this - works great:
formatted_text_box([{:text=>"Google", :link=>"https://google.com", :color=>"0000ee"}])

Agile web development with rails - Ajax

i m using rails 2.3.3 and web browser Firefox i have added ajax and java script and it is working too but i have to reload the page every time when i press Add to Cart button to show item additionn in the side bar it don’t show it without reloading.
anyone please help me how can it show item addition in side bar when i press Add to Cart button with out reloading the page?
If you haven't already done so, install Firebug for Firefox, for these reasons:
it'll tell you if you have a Javascript error.
it'll show you if your Ajax request is being received and its contents.
you can inspect your page elements such as the cart to see if it's set to be shown, if the ID is correct, etc. in a much faster way than browsing through the source.
and more (CSS, etc).
If you can't figure it out by looking at the Firebug console, and since you're following a tutorial, why don't you download the Depot source code and compare it with your own to see what you're doing wrong.
If you have the book, the complete source is listed at the end of the book. You can also download the source from here.
The standard ajax helper methods are link_to_remote, form_remote_tag, form_remote_for, button_for_remote. (I might have missed a few.) If you're not using one of them, you could be doing something wrong.
If you're using one of the helper methods with remote as part of the name, you might be missing the update option or the update option is pointed to the wrong html element.
For a form_remote_tag helper:
form_remote_tag(:url => {:controller => controller_name, :action => action_name, :id => id},
:update => element_to_update)
The element_to_update should be the html element's id that you're updating.

Resources