How do I include a controller method from one file, inside a controller method of a different file?

15 views
Skip to first unread message

desbest

unread,
Nov 12, 2012, 7:52:35 AM11/12/12
to ram...@googlegroups.com
I want to run makenew.rb def dispatch(*args) ...... end inside cron.rb def subscriptions .... end

Michael Trommer

unread,
Nov 12, 2012, 7:55:46 AM11/12/12
to ram...@googlegroups.com
I would make a modul. 

Make the logic in Makenew#dispatch in a modul, and include the Module in both controllers.


On 12 November 2012 13:52, desbest <afanint...@gmail.com> wrote:
I want to run makenew.rb def dispatch(*args) ...... end inside cron.rb def subscriptions .... end

--
You received this message because you are subscribed to the Google Groups "Ramaze" group.
To view this discussion on the web visit https://groups.google.com/d/msg/ramaze/-/bsaxHgGN7wUJ.
To post to this group, send email to ram...@googlegroups.com.
To unsubscribe from this group, send email to ramaze+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ramaze?hl=en.



--
So far,
 -- Michael 'entropie' Trommer

Whenever people agree with me I always feel I must be wrong.
  -- Oscar Wilde

tynamite

unread,
Nov 12, 2012, 8:12:08 AM11/12/12
to ram...@googlegroups.com
That leads me to my next question. How do I include a helper?

I have this inside app.rb require __DIR__('helpers/extrahelpers')
And when I put helper :extrahelpers inside controllers/main.rb it says that the model could not be found.

models/extrahelpers.rb is 

module Ramaze
  module Helper
    module SideBar

      def generate(current=nil)
        # Generate some HTML that will make the side bar
        sidebar = "<div class="sd"><h1>This is a sidebar</h1>"
        sidebar<< "<ul>"
        sidebar<< "<li>First item</li>"
        sidebar<< "<li>Second item</li>"
        sidebar<< "</ul></div>"

        sidebar.to_s
      end

    end
  end
end

Yorick Peterse

unread,
Nov 12, 2012, 8:13:30 AM11/12/12
to ram...@googlegroups.com
Desbest,

This is because the name of the module does not match the file name. In
this case the file name should be renamed to "sidebar.rb" *or* the
helper should be renamed to "ExtraHelpers".

Yorick

tynamite

unread,
Nov 12, 2012, 8:29:26 AM11/12/12
to ram...@googlegroups.com
Have you any idea why this code for extrahelpers.rb is producing an error?

syntax error, unexpected $end (SyntaxError) end     endn '12'

module Ramaze
  module Helper
    module ExtraHelpers

      def generate(current=nil)
        # Generate some HTML that will make the side bar
        return '12'
      end

    end
  end
end


--
You received this message because you are subscribed to the Google Groups "Ramaze" group.
To post to this group, send email to ram...@googlegroups.com.
To unsubscribe from this group, send email to ramaze+unsubscribe@googlegroups.com.

Yorick Peterse

unread,
Nov 12, 2012, 9:12:32 AM11/12/12
to ram...@googlegroups.com
Desbest,

I'd start with uploading your actual code to a pastebin and submitting
the link here. The provided block of code runs fine and I doubt that's
the block of code causing the error.

Yorick

tynamite

unread,
Nov 12, 2012, 11:59:11 AM11/12/12
to ram...@googlegroups.com
It really is that code causing the trouble. I've posted it here.


Reply all
Reply to author
Forward
0 new messages