Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Getting troubles with routes and locales, getting an exception on one route, sound strange...
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :set_locale
def set_locale
I18n.locale = params[:locale] || I18n.default_locale
@language = I18n.locale
end
end
# other stuffs before
<div id="transition-bottom" class="transition">
<div class="inner-transition c100">
<ul>
<li class="films"><%= link_to t(:all_movies), films_path %></li> # http://localhost:3000/fr/films
<li class="panorama"><%= link_to t(:panorama), panorama_path %></li> # http://localhost:3000/fr/panorama
<li class="small"><%= link_to t(:movie_proposition), propositions_path %></li> # http://localhost:3000/propositions <= Missign /fr here (and only here !)
<li class="qui small"><%= link_to t(:who_are_we), about_us_path %></li> # http://localhost:3000/fr/about_us
<li class="utilisation small"><%= link_to t(:cgu), utilisation_path %></li> # http://localhost:3000/fr/utilisation
<li class="mentions small"><%= link_to t(:mentions), mentions_path %></li> # http://localhost:3000/fr/mentions
</ul>
</div>
</div>
# other stuffs after
class PropositionsController < ApplicationController
layout 'application_white'
def index
@proposition = Proposition.new
@proposition.files.build
end
# POST /propositions
# POST /propositions.json
def create
@proposition = Proposition.new(params[:proposition])
respond_to do |format|
if @proposition.save
logger.info { "proposition is valid" }
format.html { redirect_to :index, notice: I18n.t(:proposition_submitted) }
format.json { render json: @proposition, status: :created, location: @proposition }
else
logger.info { "proposition is unvalid" }
format.html { render 'index' }
format.json { render json: @proposition.errors, status: :unprocessable_entity }
end
end
end
end
GET /:locale/propositions(.:format) propositions#index {:locale=>/en|fr/}
POST /:locale/propositions(.:format) propositions#create {:locale=>/en|fr/}
GET /:locale/propositions/new(.:format) propositions#new {:locale=>/en|fr/}
edit_proposition GET /:locale/propositions/:id/edit(.:format) propositions#edit {:locale=>/en|fr/}
GET /:locale/propositions/:id(.:format) propositions#show {:locale=>/en|fr/}
PUT /:locale/propositions/:id(.:format) propositions#update {:locale=>/en|fr/}
DELETE /:locale/propositions/:id(.:format) propositions#destroy {:locale=>/en|fr/}
MyApplication::Application.routes.draw do
scope "/:locale/", :locale => /en|fr/ do
resources :propositions, only: [:index]
resources :films, only: [:index, :show]
resources :articles, only: [:index, :show], as: :panorama
...
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment