Skip to content

Help on override a create method #10

@realleoman

Description

@realleoman

Hi, I have created my Resources files but I'm missing one part (still understanding how this part works)

I have a resources that PUTs a URL into my database using the following sentence =>

curl -i -H "Accept: application/vnd.api+json" -H 'Content-Type:application/vnd.api+json' -X POST -d '{"data": {"type":"urls", "attributes":{"url":"http://www.myurl.com"}}}' http://localhost:3001/api/v1/urls

My question is:
How do I allow my controller (or resource) to parse the HTML and extract some tags from it?

I created the following method on my urls_controller just to test if it works:

def create
@url = Url.new(params[:data])
parse_url = Nokogiri::HTML(open(params[:data][:attributes][:url].to_s))
puts parse_url.class # => Nokogiri::HTML::Document
@url.save
end

but my console shows this error

ActiveModel::ForbiddenAttributesError (ActiveModel::ForbiddenAttributesError):
app/controllers/api/v1/urls_controller.rb:7:in `create'

and the URL is not printed on my console nor the url is saved on my urls table.

Any suggestion?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions