1

have some question when generate controller appear some comment

i want to know use importance with these line

 # GET /folusers
 # GET /folusers.json
 def index 

first question rails generate json file. can use instead of api version .

# POST /folusers
# POST /folusers.json
def create

second question how access create method by json


final question need to create mobile app and connect with db are enough use generate in controller or use api version ?

13
  • You can only "API mode" in Rails 5+ btw Commented Jun 23, 2018 at 9:07
  • I have rails app how to make api in controller generate json for each method is this enough ? Commented Jun 23, 2018 at 9:14
  • @Sdadad sourcey.com/building-the-prefect-rails-5-api-only-app Commented Jun 23, 2018 at 9:15
  • 3
    @Sdadad i think u need to learn basics of rails first. Commented Jun 23, 2018 at 9:19
  • 1
    @Sdadad so far is the same engine, just light weight body for API version without views/assets. print middleware list rake middleware Commented Jun 23, 2018 at 9:29

1 Answer 1

1

In order to make existing action or new action into API action which can be used from your API app you just need to write following code in the action for JSON request(AJAX or API call) render json: @user or can use JSON builder gem which is good option to create specific json for your specific need.

You can handle HTML(Browser) or JSON(API) request using respons_to method of Rails

Sign up to request clarification or add additional context in comments.

4 Comments

thanks @Sandeep Garg which best use JSON builder gem vs api versioning rails?
Have a look on both I think both have different uses
can explain best way to make API for exist rails app to connect mobile app @Sandeep Garg
Use JSON builder gem to make json required by mobile app

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.