Ruby on Rails
108
Вклад в тег
export function loadInfo() {
return dispatch => {
dispatch({
type: 'LOAD_INFO_REQUESTED'
});
request.get(
Routes.root_path(),
{headers: {'Accept': 'application/json'}}
)
.then(result => {
dispatch({
type: 'LOAD_INFO_OK',
info: result.data
})
})
.catch(result => {
dispatch({
type: 'LOAD_INFO_FAIL',
errors: result.statusText
})
})
}
}
const defaultState = { loading: false, info: null, errors: null };
export default function info(state = defaultState, action) {
switch (action.type) {
case LOAD_INFO_REQUESTED:
return { loading: true };
case LOAD_INFO_OK:
return { loading: false, info: action.info, errors: null };
case LOAD_INFO_FAIL:
return { loading: false, info: null, errors: action.errors };
default:
return state;
}
}
@connect(state => ({
info: state.info
}))
class Info extends Component {
componentDidMount() {
const { dispatch } = this.props;
dispatch(loadInfo()) // Вызываем загрузку
}
render() {
const { loading, info, errors } = this.props.info;
if (loadind) { return (<div>Loading</div>) }
if (errors != null) { return (<div>Error!</div>) }
return (
<div>
{ info }
</div>
);
}
}
И стоит ли заниматься изучением Ruby, без дальнейшего освоения RoR?
= form_for [:admin, @post], html: { multipart: true } do |f|
= f.file_field :images, multiple: true
params[:images].each do |image|
@post.photos.build(image: image)
end