This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useState } from 'react'; | |
| import { IoMdClose } from 'react-icons/io'; | |
| import { produce } from 'immer'; | |
| import { generate } from 'shortid' | |
| const StartupForm = () => { | |
| const [tags, setTags] = useState([ | |
| { | |
| id: '1', | |
| name: 'Physic' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import AuthStore from './auth'; | |
| import TopicStore from './topic'; | |
| class Store { | |
| constructor() { | |
| this.authStore = new AuthStore(this); | |
| this.topicStore = new TopicStore(this); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def changeset(%User{} = user, attrs) do | |
| # Conditional req validation | |
| required_fields = if attrs[:provider] do | |
| [:username, :email] | |
| else | |
| [:username, :email, :password] | |
| end | |
| user | |
| |> cast(attrs, @required_fields, @optional_fields) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe 'POST /books' do | |
| # valid payload | |
| let(:valid_attributes) do | |
| # send stringify json payload | |
| { | |
| "title": "Learn Elm", | |
| "user_id": user.id, | |
| "image": "example.jpg" | |
| }.to_json | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class BookSerializer < ActiveModel::Serializer | |
| attributes :id, :title, :description, :created_by, :created_at | |
| has_many :comments | |
| def comments | |
| object.comments.index_by(&:id) # NoMethodError (undefined method `id' for [2]:Array): | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| return ( | |
| <div> | |
| <Switch location={isModal ? this.prevLocation : location}> | |
| <Route path="/" exact component={withAuth(Main)} /> | |
| <Route path="/auth/register" exact component={Register} /> | |
| <Route path="/auth/login" exact component={Login} /> | |
| <Route path="/users" exact component={withAuth(ListUsers)} /> | |
| <Route | |
| path='/clients/:id/edit' | |
| render={() => withAuth( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Home = (function() { | |
| var links = $("[data-behavior~=anchor-link]"); | |
| var cover = $('.cover'); | |
| var init = function() { | |
| $(window).on("load", coverFadeOut); | |
| } | |
| var coverFadeOut = function() { | |
| cover.fadeOut(1000, function() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def parse_errors | |
| { | |
| errors: { | |
| questions: @post.questions.enum_for(:each_with_index).collect { |question, index| | |
| { | |
| index => question.errors.messages | |
| } unless question.valid? | |
| }.inject({}, :merge).transform_values {|v| v.transform_values &:first } | |
| }.merge!(@post.errors.messages) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Change this | |
| { | |
| "addresses[0].city": "this is an error message" | |
| } | |
| // To this | |
| { | |
| addresses: { | |
| 0: { | |
| city: "this is an error message" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| result: [1, 2], | |
| entities: { | |
| articles: { | |
| 1: { | |
| id: 1, | |
| title: 'Some Article', | |
| author: 1 | |
| }, | |
| 2: { |
NewerOlder