Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help on override a create method #10

Open
realleoman opened this issue May 31, 2018 · 0 comments
Open

Help on override a create method #10

realleoman opened this issue May 31, 2018 · 0 comments

Comments

@realleoman
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant