0
我的麻烦是我有2个控制器(文章&新闻),当我编辑文章我的更新被保存到分贝。但是当我尝试做新闻一样,我得到这个错误rails mixes id and locale post params
Started PUT "/1" for 127.0.0.1 at 2012-11-21 10:30:17 +0200
Processing by NewsController#index as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"OyzVdh0yLz4fGAPwU+tKzuy8B5Wb0exV4+4OjE5UHt8=", "news"=>{"title"=>"fsf", "text"=>"<p>fsdfsfds</p>"}, "commit"=>"Update News", "locale"=>"1"}
1 translation's not available
,我没有看到这两个动作之间的任何差别在代码
路线
scope '(:locale)' do
get 'articles/autocomplete_article_title'
resources :users
resources :news do
end
resources :articles do
end
# match "/news*tail" => 'news#index'
root :to => 'News#index', as: 'news'
end
请帮帮忙!
非常感谢提前!
更新1
的错误似乎是在路由(因为这是抛出错误
def set_locale_from_params
if params[:locale]
if I18n.available_locales.include?(params[:locale].to_sym)
I18n.locale = params[:locale]
else
flash.now[:notice] =
"#{params[:locale]} translation\'s not available"
logger.error flash.now[:notice]
end
end
end
def default_url_options
{locale: I18n.locale}
end
更新2
的地方,发生错误时,这是则params的转储。此处没有id字段
{"utf8"=>"✓", "_method"=>"put", "authenticity_token"=>"OyzVdh0yLz4fGAPwU+tKzuy8B5Wb0exV4+4OjE5UHt8=", "news"=>{"title"=>"fsf", "text"=>"<p>fsdfsfds</p>"}, "commit"=>"Update News", "controller"=>"news", "action"=>"index", "locale"=>"1"}
更新3
试图设置scope '(:locale)', :locale => /en|ru/ do
在路由中,因为在这里http://guides.rubyonrails.org/i18n.html#setting-the-locale-from-the-url-params没有帮助。
更新4
问题是,form_for指向/:id url,它被根路由覆盖。所以改变的form_for到form_for(@news, url: news_path(@news))
,不得不把这里的本地搜索......那怎么办
如果从根路径中删除“as:'news'”怎么办? –
不,没有帮助 – Elmor
我已经发布了答案 – Elmor