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!

4

1 回答 1

1

如果我理解这个问题:您想在服务器通过链接获取徽标后添加一个页面?页面将使用此徽标创建。如果是这样,那么服务器本身应该使用例如mechanize跟踪该链接,并在那里找到指向徽标的链接。例如:

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

更复杂的例子:http ://caldeas.com/2010/08/01/using-mechanize-to-download-images-from-stock-exchange/

这可能不是您想要的,但它会解决您的问题。

于 2012-05-22T08:18:58.407 回答