我想翻译我的应用程序的视图,因为我正在使用partial来为每个视图呈现标题,如下所示:
<%=t "#{controller.controller_name.capitalize} #{controller.action_name}" %>
......我一直在努力翻译它们.如何翻译controller.action_name自定义翻译文件?
我试图访问这样的动作名称:
parkings:
index: "Parkings index"
new: "New %{model}"
Run Code Online (Sandbox Code Playgroud)
它的许多不同的变化,但每一个都失败了.你可以帮帮我吗?
这是我的控制器的一个片段:
def new
@parking = Parking.new
end
def create
@parking = Parking.new(parking_params)
if @parking.save
redirect_to @parking, notice: t(:parking_created)
else
render action: 'new'
end
end
Run Code Online (Sandbox Code Playgroud)
谢谢.
我正在使用Draper来装饰我的视图并从中移出一些逻辑但是我正在努力解决这个问题 - 如何使用Bootstrap Pagination设置Draper(will_paginate)?
默认我有这个:
delegate_all
Run Code Online (Sandbox Code Playgroud)
从Draper文档我尝试添加这个:
delegate :current_page, :per_page, :offset, :total_entries, :total_pages
Run Code Online (Sandbox Code Playgroud)
但是在视图中调用分页时仍然会返回错误.我的控制器定义装饰和分页,如下所示:
@matches = Match.all.paginate(:per_page => 10, :page => params[:page]).decorate
Run Code Online (Sandbox Code Playgroud)
我的观点是:
<%= will_paginate @matches, renderer: BootstrapPagination::Rails %>
Run Code Online (Sandbox Code Playgroud)
更新:
class ApplicationDecorator < Draper::Decorator
def self.collection_decorator_class
PaginatingDecorator
end
end
class PaginatingDecorator < Draper::Decorator
# support for will_paginate
delegate :current_page, :total_entries, :total_pages, :per_page, :offset
end
class PlayerDecorator < ApplicationDecorator
delegate_all
decorates_association :matches
class MatchDecorator < ApplicationDecorator
delegate_all
decorates_association :players
Run Code Online (Sandbox Code Playgroud) ruby-on-rails decorator will-paginate twitter-bootstrap draper