Reputation: 343
Im using a gem called MetaInspector to scrape data from different websites. Im building a site where i can collect data from different sites but am having trouble setting up. I have a model called site with a title and a url both strings. When i create a new "site" the name will come out as example.com/"sitename" and in there i would like to have the data just from that site. I kinda have an idea to this by adding page = MetaInspector.new to the new method but cant see how i can set a url in there. I can show my controller and other info if needed.
Controller
class Admin::SitesController < Admin::ApplicationController
def index
@sites = Site.all
end
def show
@site = Site.friendly.find(params[:id])
end
def edit
@site = Site.friendly.find(params[:id])
end
def update
@site = Site.friendly.find(params[:id])
if @site.update(site_params)
redirect_to admin_path
else
render :edit
end
end
def destroy
@site = Site.friendly.find(params[:id])
@site.destroy
if @site.destroy
redirect_to admin_path
end
end
def new
@site = Site.new
end
def create
@site = Site.new(site_params)
if @site.save
redirect_to admin_path
else
render :new
end
end
private
def site_params
params.require(:site).permit(:title, :url)
end
end
Upvotes: 0
Views: 110
Reputation: 15550
If I understand correct you want to show the metainfo for a Site
you have added. You could put that code in the show
action of the controller:
def show
@site = Site.friendly.find(params[:id])
@page = MetaInspector.new(@site.url)
end
And update the show.html.erb
template to display info about @page
, ie:
<%= @page.title %>
Upvotes: 1