Using url_helpers inside lib class in rails 4 -


A lib class is used to get an email in my Rail application. The email receiver parses the square email and posts it to an application controller using an HTTP response. Code is displayed for:

  uri = 'http: // localhost: 3000 / incoming_mail' body = {'from' = & gt; From, 'to' = & gt; For, 'topic' = & gt; Subject, 'message' = & gt; Message} response = net :: HTTP :: post_form (URI.parse (uri), body)  

The problem is that I do not want to specify the full URL. Is there a way to use 'incoming_mail_path' instead of 'localhost: 3000 / incoming_mail'? I tried to add it:

  contains rail. Application Light_url_holder  

but it is not working and returns the following error:

   

Can anyone suggest a solution for it?

I am posting the entire class here (the included statement has been updated):

  Required 'Mail' Requires 'Net / https' Requires 'Net / http' required 'uri' category EmailReceiver Rails included Application.routes.url_helpers attr_accessor: url def initialize submit (content) mail = mail.read_from_string (content) body = mail.body.decoded = Mail.from.first = mail.to.first topic = mail.subject if mail.multipart? Part = mail.parts.select {| P | | P.content_type = ~ / text \ / plain /}. Before parting nil until part.nil? Message = part.body.decoded end and message = mail.decoded end to message.nil? URI = incoming_mail_arnal # rui = 'http: // localhost: 3000 / incoming_mail' body = {'from' = & gt; From, 'to' = & gt; For, 'topic' = & gt; Subject, 'message' = & gt; Message} response = net :: HTTP :: post_form (URI.parse (uri), body) end-end handler = EmailReceiver.new handler (STDI reader)  

debugging:

After reading your comments, I thought that you are running it as a Ruby script which Also recognize

Before learning about how to incorporate all the requirements in the file, I tried to run the file through the Rail Environment (unless the server came Was running from the area):

  cat sample.email | Error found for  incoming_mail_url :     prior>  missing the host to link! Please set as  incoming_mail_path  successfully executed as  /   

: host parameter, set default_url_options [: host] or set: only_path To be true (ArgumentError) incoming_mail (which you do not need it)


Conclusion:

This means that whatever you do, unless you have a file from the server (pre: initial) then the host will not be present.

When you run this module on your server, then Route via again Url_helpers which you have added.


Alternative Tips:

Mani is a rail engine that provides a finishing point for services that converts incoming email into HTTP POST requests. Parsing and closes a built-in email object for a class implemented by you


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -