Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows you to easily overwrite the translation of object_name in resource_controller by adding a method called translated_object_name. #419

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions core/app/controllers/admin/resource_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def update
invoke_callbacks(:update, :before)
if @object.update_attributes(params[object_name])
invoke_callbacks(:update, :after)
resource_desc = I18n.t(object_name)
resource_desc = translated_object_name
resource_desc += " \"#{@object.name}\"" if @object.respond_to?(:name)
flash[:notice] = I18n.t(:successfully_updated, :resource => resource_desc)
respond_with(@object) do |format|
Expand All @@ -41,7 +41,7 @@ def create
invoke_callbacks(:create, :before)
if @object.save
invoke_callbacks(:create, :after)
resource_desc = I18n.t(object_name)
resource_desc = translated_object_name
resource_desc += " \"#{@object.name}\"" if @object.respond_to?(:name)
flash[:notice] = I18n.t(:successfully_created, :resource => resource_desc)
respond_with(@object) do |format|
Expand All @@ -58,7 +58,7 @@ def destroy
invoke_callbacks(:destroy, :before)
if @object.destroy
invoke_callbacks(:destroy, :after)
resource_desc = I18n.t(object_name)
resource_desc = translated_object_name
resource_desc += " \"#{@object.name}\"" if @object.respond_to?(:name)
flash[:notice] = I18n.t(:successfully_removed, :resource => resource_desc)
respond_with(@object) do |format|
Expand Down Expand Up @@ -106,6 +106,10 @@ def model_class
controller_name.classify.constantize
end

def translated_object_name
I18n.t(object_name)
end

def object_name
controller_name.singularize
end
Expand Down