我想写一些文件.
# where userid is any intger [sic]
path = Rails.root + "public/system/users/#{user.id}/style/img.jpg"
File.open(path, 'wb') do |file|
file.puts f.read
end
Run Code Online (Sandbox Code Playgroud)
执行此代码时,我收到此错误.我知道这个文件夹不存在,但File.open与w模式创建一个新的文件,如果它不存在.
为什么这不起作用?
反应路由器中是否有一种方法可以在某些组件呈现URL时相应地更改.
这是我知道的一个方法是将window.history.pushState('', '', '/componentUrl'); 在render function组件的
有没有更好的方法来实现它而route不是path道具,Route因为path= 'someurl'无论什么时候someurl被访问someComponent应该渲染
但是反过来,只要someComponent 渲染网址应该更改为someurl我在内部条件渲染的上下文中使用此senerio component.
嗨,我正在为应用程序构建一个api部分.我的所有api相关控制器都驻留在app/controllers/api目录中.
我担心的是,application_controller有一个过滤器before_action
:authenticate_user!,所以我必须在登录模式下访问api.
我目前的解决方案:我正在添加目录 skip_before_action :authenticate_user!中的所有控制器
app/controllers/api..
问题:我必须写入所有控制器,我有大约80个控制器
我的期望:有没有办法我可以application_controller自己写这样的
事情:before_action:authenticate_user !,除了:[ all the controllers which are in api directory]
最初一切都很好,我有一个类似的组件.这个
class A extends React.Component {
constructor(props) {
super(props);
this.childRef = null
}
componentDidMount() {
this.childRef = this.refs.b
// now I can call child function like this
this.childRef.calledByParent()
}
render(){
<B ref = "b"/>
}
}
Run Code Online (Sandbox Code Playgroud)
在其他文件中
class B extends React.Component {
calledByParent(){
console.log("i'm called")
}
render(){
<div> hello </div>
}
}
export default B
Run Code Online (Sandbox Code Playgroud)
到这里它工作正常,但当我做这样的事情 class B export default connect(mapStateToProps, mapDispatchToProps)(B)
它不起作用.我从react-redux导入了connect
如何从axios内部调用函数,然后下面是我的代码不起作用
handleClick(userid){
axios.get(
"http://localhost:4000/user/"+userid+"/items.json")
.then(function (response) {
dispatch(this.buildhtml.bind(response))
})
}
buildhtml(response){
console.log("m called")
}
Run Code Online (Sandbox Code Playgroud)
buildhtml函数未执行!任何的想法
ActiveRecord和编写原始查询之间有什么区别??在这种情况下,应该采用在rails app中编写原始查询的方式。
我知道这个问题已经在这个论坛上问过了。但它对我不起作用。
我的要求是这样的
if request.type.json?
#disbale `ActionController::InvalidAuthenticityToken`
else
# enable `ActionController::InvalidAuthenticityToken`
end
Run Code Online (Sandbox Code Playgroud)
任何的想法 !!如何实现这个?