Creating your own global methods (like params, etc.)?

I put this in my app.rb:

public
def member
if @member.nil?
@member = Member.find_by_username(‘joe’)
else
@member
end
end

I figured I’d be able to use it in templates like so:

text “Hi #{member.name}!”

text “Hi #{@helpers.member.name}!” # also tried this since I’m using

markaby

but that gives an “undefined method ‘member’” error. However, if I put
this in app.rb:

before_filter :member

it works. What’s up with that?

At any rate, what’s the proper voodoo for creating your own “global”
methods like params, request, etc.?

Thanks,
Joe

I put this in my app.rb:

public
def member
if @member.nil?
@member = Member.find_by_username(‘joe’)
else
@member
end
end

I figured I’d be able to use it in templates like so:

text “Hi #{member.name}!”

text “Hi #{@helpers.member.name}!” # also tried this since I’m using

markaby

but that gives an “undefined method ‘member’” error. However, if I put
this in app.rb:

Views can only see helper methods- put “member” in app_helper.rb if you
want it to be visible from views, or at least declare

helper_method :member

in app.rb

before_filter :member

it works. What’s up with that?

No problem here- before_filter belongs to ActionController, and things
in app.rb are visible from there.

At any rate, what’s the proper voodoo for creating your own “global”
methods like params, request, etc.?

You’ve got the idea- just need some visibility tweaks.

BTW, congrats on the MUDCRAP certification…I’m planning on
starting on online study course for MUDCRAP soon. PayPal will be
gleefully accepted.

  • Danny

Danny B. wrote:

I put this in my app.rb:

public
def member
if @member.nil?
@member = Member.find_by_username(‘joe’)
else
@member
end
end

I figured I’d be able to use it in templates like so:

text “Hi #{member.name}!”

text “Hi #{@helpers.member.name}!” # also tried this since I’m using

markaby

but that gives an “undefined method ‘member’” error. However, if I put
this in app.rb:

Views can only see helper methods- put “member” in app_helper.rb if you
want it to be visible from views, or at least declare

helper_method :member

in app.rb

before_filter :member

it works. What’s up with that?

No problem here- before_filter belongs to ActionController, and things
in app.rb are visible from there.

But the member method set @member – I don’t know why ‘member’ would be
visible after the before filter runs. Unless it’s doing something wacky
like interpolating member to @member.

At any rate, what’s the proper voodoo for creating your own “global”
methods like params, request, etc.?

You’ve got the idea- just need some visibility tweaks.

BTW, congrats on the MUDCRAP certification…I’m planning on
starting on online study course for MUDCRAP soon. PayPal will be
gleefully accepted.

My life is vastly better since completing the MUDCRAP certification!
Much better pay, higher IQ, better looks, heaps of accolades from peers!

Joe

  • Danny