0

I new in rails. I trying to write redmine plugin to extend sidebar with chat. Hook works with static data. How to pass data? generated by controller?

I have simple controller and list.js.erb

$('#chat-plugin-messages').empty().append("<ul> <%= j render @messages %> </ul>");

How to call it from hook?

hook

module ChatPlugin
  class Hooks < Redmine::Hook::ViewListener
     render_on :view_projects_show_sidebar_bottom,
              :partial => 'hooks/chat/sidebar'
  end
end

upd:

View has been rendered, but controller not called. So i have nil in @messages variable.

UPD:

Code https://github.com/alex-eri/redmine-chat

This works with now, but i want render same block with .

eri
  • 3,133
  • 1
  • 23
  • 35

1 Answers1

1

I believe that you can look at this code (hook view_issues_form_details_top) and implement the similar logic in your app

gotva
  • 5,919
  • 2
  • 25
  • 35
  • i tried like this `context[:controller].send(:render, { :partial => 'hooks/chat/sidebar', :locals => {:messages => @messages} })`, but @messages in view is nil. – eri Jan 02 '14 at 17:16
  • не передается переменная во вьюху... и мне говорили, если рендер вызываешь, то рельсы вызовут соответствующий контроллер (не вызывают) или я контролленр для partial неправильно обзываю... – eri Jan 02 '14 at 17:20
  • Your phrase confuses me a lot: `View has been rendered, but controller not called`. Lets clearify: you add `before_filter` to some action where you define veariale `@messages` then you are trying to display it through hook somewhere on sidebar. Is it correct? – gotva Jan 02 '14 at 19:28
  • after django rails confuses me totally. what before_filter? i ecxept according my web searches if i write <%= render 'chat/list' %> rails call controller, then renders view, but nope. then i copy-paste code from controller to hook. in hook i defined @messages, but it does not passed to chat/list view. – eri Jan 05 '14 at 02:08