ActiveSupport::MessageVerifier::InvalidSignature

时光毁灭记忆、已成空白 提交于 2021-01-28 21:17:42

问题


I'm trying create a form in which a user can edit an existing video title and description. When sending PATCH request I get the error below. Another post on StackOverflow said that the error caused if a string is sent instead of an object, but i see an object when i console log it. Any thoughts?

video controller:

def update
        @video = Video.find(params[:id])
        if @video.update(video_params)
            render :show
        else
            render json: @video.errors.full_messages, status: 422
        end
    end

  
    def video_params 
        params.require(:video).permit(:video_title, :video_description, :owner_id, :video_url)
    end

edit container

import { connect } from  'react-redux';
import Edit from './edit';
import { fetchVideo, updateVideo } from '../../actions/video_actions';

const mSTP = ( state, ownProps ) => {
    
    return {
        // video: state.entities.videos[state.session.id],
        video: state.entities.videos[ownProps.match.params.id],
        // errors: state.errors
    }
};

const mDTP = dispatch => ({
    fetchVideo: videoId => dispatch(fetchVideo(videoId)),
    updateVideo: video => dispatch(updateVideo(video)),
});

export default connect(mSTP, mDTP)(Edit);

edit form

class Edit extends React.Component {

    constructor(props) {
        super(props)
        this.state = {
            video_id: this.props.match.params.id,
            video_title: "",
            video_description: "",
        }
        this.handleSubmit = this.handleSubmit.bind(this);
    }

    update(field) {
        return (e) => {
            this.setState({
                [field]: e.currentTarget.value
            })
        }
    }   

    handleSubmit() {
        // debugger
        //this.props.updateVideo(this.state.video_id)
        const { video_id, ...rest } = this.state
        this.props.updateVideo(video_id, { video: { ...rest } })
    }

    render() {
        return (
            <div className="edit-container">
                <form className="edit-form" onSubmit={this.handleSubmit}>
                    <label>
                        <input 
                            type="text"
                            value={this.state.video_title}
                            placeholder="Your video's title"
                            onChange={this.update("video_title")}
                        />
                        <div>{this.state.video_title}</div>
                    </label>
                    <label>
                        <input 
                            type="textarea"
                            value={this.state.video_description}
                            placeholder="Your video's description"
                            onChange={this.update("video_description")}
                        />  
                    </label>
                    <button>Edit</button>
                </form>
            </div>
        );
    }
}

export default Edit;

来源:https://stackoverflow.com/questions/62779177/activesupportmessageverifierinvalidsignature

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!