0
我想借助button_to方法創建一個按鈕,以導航到可創建新用戶友誼的頁面。爲HTTP GET請求創建按鈕:保持區域設置的問題
<%= button_to t(:add_friend), new_user_friendship_url(current_user), :method => :get, :class => "btn-success" %>
(我不想用一個鏈接,即不使用的link_to,因爲CSS框架我用的按鈕樣式比鏈接看起來要好得多)。
不幸的是,button_to不會將正確的語言環境附加爲URL參數。有什麼我可以做的嗎?
這是我的application_controller.rb其中我爲每個頁面請求設置語言環境。
class ApplicationController < ActionController::Base
before_filter :set_locale
def set_locale
I18n.locale = params[:locale] || I18n.default_locale
end
protect_from_forgery
def default_url_options(options={})
logger.debug "default_url_options is passed options: #{options.inspect}\n"
{ :locale => I18n.locale }
end
end
感謝您的建議。
你是對的,在CSS樣式的作品的鏈接,以及。當我第一次嘗試時,不知道什麼產生了不好的結果。因此,我切換到鏈接而不是按鈕。謝謝! – 2012-04-06 16:09:43