0

Im wondering on how to approach this. For simplicity lets say I submit a link from a website through javascript to my rails server. I want my rails server to create a page based off that link and pull out the logo from that page. Right now I have the code to find a logo off a webpage but not sure how I can link the two together.

My controller takes in the json post request and saves a page object but how would I know ask it to run my js and save that image location in the page object as well?

Any help would be great thanks!

1 Answer 1

1

If I understand the question: you want to add a page after the server took the logo by following the link? And the page will be created with this logo. If so, then the server itself should follow the link by using for example mechanize, and there find the link to the logo. For example:

require 'mechanize'
...
def create
  @page = Page.new(params[:page])
  link = @page.link
  agent = Mechanize.new
  page = agent.get link
  img_src = page.search("#logo").first.attributes['src']
  @page.logo = img_src
  if @page.save
  ...
end

More complex example: http://caldeas.com/2010/08/01/using-mechanize-to-download-images-from-stock-exchange/

This is probably not what you wanted, but it will solve your problem.

Sign up to request clarification or add additional context in comments.

1 Comment

the question had been resolved I forgot to look at this but it looks like you understood it perfectly and ya thats what I was looking for =) thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.