I’m a complete rails beginner and I’m trying to understand the full concepts. I’ve literally been trying to solve this problem for hours and I wanted to ask on here.
I would like to perform a JSON request to my rails app which runs on localhost. But I do not know if I am using a wrong type of JSON request software (I’m using CocoaRestClient for mac) or my code is incorrect.
I’ve observed that when I create a POST type JSON request in rails it is leaded to the create method. And what I am trying to achieve is to actually store multiple variables that I receive from JSON and later on show it on the page. I know it’s dead simple but it is really hard because I’ve tried a lot things.
My questions:
- I will be capturing the event on create method. How can I get a parameter from the JSON request. I’ve tried
@username = params[:username]but it didn’t work out. - If I ever get lucky enough to capture the parameters that is provided by the JSON in which page should I print them. I’ve tried to show on index or show pages but couldn’t manage that as well.
You have
requestvariable that in fact is instance ofActionDispatch::Requestclass. Here you have#bodymethod that return raw request body. So if you send JSON request in body you should parse it i.e.:And if you wanna display it you have 3 options:
#createmethod what is a bad idea, because this method is only to save model to DBflashobject and store it only to next request