I am new to ruby on rails and I created a simple login & registration app using ruby on rails.
I want to pass the id, username & password that I take from the form (using ruby on rails) and pass it to my php codeigniter code that inserts it to the database and fetches it back and displays as JSON output.
I have done the latter part where my php code inserts a post data to the phpmyadmin database and fetches it (used postman POST to pass value of id, username and password)
However, I no longer want to use postman. I want to post the data from the ruby on rails form that I created but I am unaware how.
My rails app runs on localhost:3000
and php on localhost:8080
I created a rails app without database by using -O
and created the form for taking id
, username
and password
input.
The php to database interaction is done and successful. Kindly help in the rails part that makes API call to php controller. Below is the code for reference.
UsersController code:
class UsersController < ApplicationController
def index
end
def create
user = User.new(token: user_params).credentials
end
private
def user_params
params.require(:user).permit(:id, :username, :password)
end
end
User model
class User
def initialize(attributes={})
@token ||= attributes[:token]
end
def credentials
#not aware of the code needed here to communicate
# or pass parameters to my php controller i.e. the API call
#that needs to be made to my php file.
end
end
routes.rb file
get '/' => 'users#index'
post '/users' => 'users#create'