complete new method create in react +rails
Step01: Make a method in backend:::::
def standard_sections
standards = Standard.all
@standards = standards.paginate(:page => params[:page], :per_page => 10)
return render json: {status: 200, data: {standard_sections: @standards.map { |s| [s.standard, s.sections] }, count: standards.count}, message: "all standards list"}
end
................................
and check it at console and hit postman find the record
Step 02:
In newFeeGroup:: add this in actioncreators : create action creators in this...from action creators
const actionCreators = {
getStandardSections: standardActions.getstandardSections
}
Step 03: component will mount section in this matter::::::
componentWillMount() {
this.props.getStandards();
this.props.getSections();
this.props.getStandardSections();
}
Step 04: map to the state
function mapState(state) {
const { standards } = state.standards;
const { standard_sections } = state.standard_sections;
return { standards, standard_sections };
}
step 05:
add standard_and_sections in feegroup
constructor(props) {
super(props);
this.state = {
feegroup: {
title: '',
description: '',
standard_and_section: '',
loaded: 0
},
submitted: false
};
step 06:
import just like this:
import { sectionActions } from '_actions';
step07:: Make a full method in standard.actions::::
function getstandardSections() {
return dispatch => {
debugger
dispatch(request());
standardService.getstandardSections()
.then(
standards => dispatch(success(standards.data)),
error => dispatch(failure(error.toString()))
);
};
function request() { return { type: standardConstants.GETALL_REQUEST } }
function success(standards) { return { type: standardConstants.GETALL_SUCCESS, standards } }
function failure(error) { return { type: standardConstants.GETALL_FAILURE, error } }
}
step08: export standard_sections from standard.actions:::::::::::::
export const standardActions = {
create,
getAll,
getPerPageStandards,
getstandardSections
};
step 09: give this request in standard.service :::::
function getstandardSections() {
console.log("getAll AuthHeader.getHeader(): ", AuthHeader.getHeader())
const requestOptions = {
method: 'GET',
headers: AuthHeader.getHeader()
};
return fetch(`${BASE_URL}standard_sections`, requestOptions).then(handleResponse);
}
step 10: in constants check it:::::::::::: i think it will not include in our work
DELETE_REQUEST: 'STANDARDS_DELETE_REQUEST',
DELETE_SUCCESS: 'STANDARDS_DELETE_SUCCESS',
DELETE_FAILURE: 'STANDARDS_DELETE_FAILURE' ,
Important Points to hitted ::
check that request is going or not to ther server for the action after debugger hit.
Comments
Post a Comment