プロジェクト

全般

プロフィール

Vote #73846

完了

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

Admin Redmine さんが3年以上前に追加. 3年以上前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
REST API_32
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
32
version_id:
90
issue_org_id:
13924
author_id:
15484
assigned_to_id:
1
comments:
11
status_id:
5
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
60
ステータス-->[Closed]

説明

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, #, 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

journals

Did you find a solution ? even I am facing the same problem
--------------------------------------------------------------------------------
Could you please post a sample plugin crashing?
--------------------------------------------------------------------------------
The file index.api.rsb is in \redmine-2.3.1\plugins\smiles\app\views\timelog
<pre>
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
</pre>
the error log is
<pre>
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'
</pre>
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
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_
--------------------------------------------------------------------------------
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

--------------------------------------------------------------------------------
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?
--------------------------------------------------------------------------------
with redmine 3 you also have to copy/paste views/issues/index.pdf.erb and views/issues/show.pdf.erb :(
--------------------------------------------------------------------------------
Fixed in r14375.
--------------------------------------------------------------------------------
Hi! It would be nice if this patch was backported to the 2.6.x branch.
Thank you!
--------------------------------------------------------------------------------
For *redmine 2.6*, i fixed it by changing one line in *redmine_root/config/initializers/10-patches.rb*

*Change this block of code*

<pre>
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
</pre>

*TO*
<pre>
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
</pre>
--------------------------------------------------------------------------------

Admin Redmine さんが3年以上前に更新

  • カテゴリREST API_32 にセット
  • 対象バージョン3.1.0_90 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0