Project

General

Profile

Actions

Defect #13924

closed

Error when using views/issues/index.api.rsb in a plugin

Added by Dominique Lederer over 11 years ago. Updated about 9 years ago.

Status:
Closed
Priority:
Normal
Category:
REST API
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

when i overwrite index.api.rsb in a plugin (just copied the original file to the plugin), visiting /issues via web browser causes an error:

ActionView::Template::Error (No builder for format ):
    1: api.array :issues, api_meta(:total_count => @issue_count, :offset => @offset, :limit => @limit) do
    2:   @issues.each do |issue|
    3:     api.issue do
    4:       api.id issue.id
  lib/redmine/views/builders.rb:29:in `for'
  app/controllers/issues_controller.rb:83:in `block (2 levels) in index'
  app/controllers/issues_controller.rb:82:in `index'
Ruby version              1.9.3 (x86_64-linux)
RubyGems version          1.8.24
Rack version              1.4
Rails version             3.2.13
Active Record version     3.2.13
Action Pack version       3.2.13
Active Resource version   3.2.13
Action Mailer version     3.2.13
Active Support version    3.2.13
Middleware                Rack::Cache, ActionDispatch::Static, Rack::Lock, #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x00000003200168>, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Callbacks, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, ActionDispatch::Head, Rack::ConditionalGet, Rack::ETag, ActionDispatch::BestStandardsSupport, OpenIdAuthentication
Application root          /opt/bitnami/apps/redmine/htdocs
Environment               production
Database adapter          mysql2
Database schema version   20130217094251
Actions #1

Updated by Vivek Jain over 11 years ago

Did you find a solution ? even I am facing the same problem

Actions #2

Updated by Etienne Massip over 11 years ago

Could you please post a sample plugin crashing?

Actions #3

Updated by Vivek Jain over 11 years ago

The file index.api.rsb is in \redmine-2.3.1\plugins\smiles\app\views\timelog

api.array :time_entries, api_meta(:total_count => @entry_count, :offset => @offset, :limit => @limit) do
  @entries.each do |time_entry|
    api.time_entry do

      spent_on = time_entry.spent_on.present? ? time_entry.spent_on.strftime('%d-%m-%Y') : ''
      created_on = time_entry.created_on.present? ? time_entry.created_on.strftime('%d-%m-%Y') : ''
      updated_on = time_entry.updated_on.present? ? time_entry.updated_on.strftime('%d-%m-%Y') : ''

      api.id time_entry.id
      pi.project(:id => time_entry.project_id, :name => time_entry.project.name) unless time_entry.project.nil?
      api.issue(:id => time_entry.issue_id) unless time_entry.issue.nil?
      api.employee(:id => time_entry.user.employee_id) unless time_entry.user.nil?
      api.user(:id => time_entry.user_id, :name => time_entry.user.name) unless time_entry.user.nil?
      api.activity(:id => time_entry.activity_id, :name => time_entry.activity.name) unless time_entry.activity.nil?
      api.hours time_entry.hours
      api.comments time_entry.comments
      api.spent_on spent_on
      api.created_on created_on
      api.updated_on updated_on
      render_api_custom_values time_entry.custom_field_values, api
    end
  end
end

the error log is
 Rendered plugins/smiles/app/views/timelog/index.api.rsb within layouts/base (0.0ms)
Completed 500 Internal Server Error in 815ms

ActionView::Template::Error (No builder for format ):
    1: api.array :time_entries, api_meta(:total_count => @entry_count, :offset => @offset, :limit => @limit) do
    2:   @entries.each do |time_entry|
    3:     api.time_entry do
    4:
  lib/redmine/views/builders.rb:28:in `for'
  app/controllers/timelog_controller.rb:64:in `block (2 levels) in index'
  app/controllers/timelog_controller.rb:51:in `index'

Actions #4

Updated by Kumar Akarsh about 11 years ago

Any update on this?
In my plugin I am overriding both issues/index.api.rsb and issues/show.api.rsb. Its working fine for show.api.rsb but is giving error for index.api.rsb.

Actions #5

Updated by Kumar Akarsh about 11 years ago

After trying out few things I eventually figured out a solution for this. If you are overriding api responses i.e views/issues/index.api.rsb in a plugin, you need to override the html view of that action in the plugin as well. So you just need to copy views/issues/index.html.erb to your plugin views.

cp app/views/issues/index.html.erb plugins/myplugin/app/views/index.html.erb

Actions #6

Updated by Dominique Lederer almost 11 years ago

Kumar Akarsh wrote:

After trying out few things I eventually figured out a solution for this. If you are overriding api responses i.e views/issues/index.api.rsb in a plugin, you need to override the html view of that action in the plugin as well. So you just need to copy views/issues/index.html.erb to your plugin views.

cp app/views/issues/index.html.erb plugins/myplugin/app/views/index.html.erb

that does work, thanks

Actions #7

Updated by Vincent Robert almost 10 years ago

Copy/Pasting views/issues/index.html.erb to the plugin views do fix the error, but we should be able to override the API without modifying the HTML view. Any way to fix the original bug?

Actions #8

Updated by Dominique Lederer over 9 years ago

with redmine 3 you also have to copy/paste views/issues/index.pdf.erb and views/issues/show.pdf.erb :(

Actions #9

Updated by Jean-Philippe Lang over 9 years ago

  • Status changed from New to Closed
  • Assignee set to Jean-Philippe Lang
  • Target version set to 3.1.0
  • Resolution set to Fixed

Fixed in r14375.

Actions #10

Updated by Nicolas Rodriguez over 9 years ago

Hi! It would be nice if this patch was backported to the 2.6.x branch.
Thank you!

Actions #11

Updated by Ramiz Raja Chaudhry about 9 years ago

For redmine 2.6, i fixed it by changing one line in redmine_root/config/initializers/10-patches.rb

Change this block of code

class Resolver
    def find_all(name, prefix=nil, partial=false, details={}, key=nil, locals=[])
      cached(key, [name, prefix, partial], details, locals) do
        if details[:formats] & [:xml, :json]
          details = details.dup
          details[:formats] = details[:formats].dup + [:api]
        end
        find_templates(name, prefix, partial, details)
      end
    end
  end

TO

class Resolver
    def find_all(name, prefix=nil, partial=false, details={}, key=nil, locals=[])
      cached(key, [name, prefix, partial], details, locals) do
        if (details[:formats] & [:xml, :json]).any?
          details = details.dup
          details[:formats] = details[:formats].dup + [:api]
        end
        find_templates(name, prefix, partial, details)
      end
    end
  end

Actions

Also available in: Atom PDF