Ruby on Rails Tuesday, September 26, 2017



On Tuesday, September 26, 2017 at 12:15:29 PM UTC-4, Walter Lee Davis wrote:

> On Sep 26, 2017, at 11:27 AM, fugee ohu <fuge...@gmail.com> wrote:
>
> I came across this mailboxer example http://josephndungu.com/tutorials/private-inbox-system-in-rails-with-mailboxer halfway down the  page where the author puts some helpers in application_controller.rb ( helper_method :mailbox, :conversation) Why does he put them there? Why not create them as files under app/helpers ?
>

You'd have to ask the developer to be sure, but my guess is that they don't want you to have to repeat yourself -- the helpers are coming from the gem, and the helper_method method just registers them with the application so they can be found. You would do the same thing if you had written a helper and wanted it to be available everywhere. I have seen Rails apps with the line: helper_method :all in the application_controller.rb, but admittedly, that was a long time ago, and I think that became the default. Thinking through this as I write, my suspicion is that whatever replaced helper_method :all did so with a read through the helpers folder, finding all the helper modules and requiring them into the Application Controller. But that's just a guess. So as a gem author, the developer is probably trying to find a good balance between getting the code they've written into your application through "magic" or deliberate action on your part (so you can get a sense for how things are hooked into your app).

Walter

> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/b89175fb-051c-46df-a542-2f0e0d4f2e0c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


Thanks Walter

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/02568e7e-2af7-4186-938b-91ad47f72bf2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment