GVKun编程网logo

rails resce_from 设置错误页面

6

在这篇文章中,我们将为您详细介绍railsresce_from设置错误页面的内容。此外,我们还会涉及一些关于Error:(47,13)Failedtoresolve:com.facebook.fres

在这篇文章中,我们将为您详细介绍rails resce_from 设置错误页面的内容。此外,我们还会涉及一些关于Error:(47, 13) Failed to resolve: com.facebook.fresco:fresco:0.11.0、NoMethodError in SessionsController#create from a rails program、PHP date_create_from_format 使用对象给出 bool(false) 错误、Rails: Access to current_user from within a model in Ruby on Rails的知识,以帮助您更全面地了解这个主题。

本文目录一览:

rails resce_from 设置错误页面

rails resce_from 设置错误页面

1、设置 ActiveRecord find 方法没找到不报错,调用一个显示 404 页面的方法

class ApplicationController < ActionController::Base
  rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found

  def record_not_found
    render ''record_not_found''
    # ....
    true
  end
end

2、设置 500 页面

rescue_from RuntimeError, with: :render_error

def render_error 
    render ''error_500''status: 500layout: ''public''
end

  3、其他等等错误页面,可以写到一个方法中

    rescue_from Exceptionwith:render_error unless Rails.env.development?
    rescue_from RuntimeErrorwith:render_error unless Rails.env.development?
    rescue_from ActionController::UnknownControllerwith:render_not_found unless Rails.env.development?
    rescue_from ActionController::UnknownActionwith:render_not_found unless Rails.env.development?




Error:(47, 13) Failed to resolve: com.facebook.fresco:fresco:0.11.0

Error:(47, 13) Failed to resolve: com.facebook.fresco:fresco:0.11.0

Fresco 使用及问题

  1. Android Studio 使用远程依赖时下载不了 jar 包的解决方法 // 需要添加以下 maven 库,否则使用远程依赖时,可能无法下载 fresco 数据:compile (''com.facebook.fresco:fresco:0.4.0+'') // Error:(126, 14) Failed to resolve: com.facebook.fresco:fresco:0.4.0+
allprojects {
    repositories {
        mavenCentral()
    }
}
  1. Execution failed for task '':imagepipeline:ndk_build_gifimage''. 如果你遇到这个错误,多半是找不到 ndk 环境导致的。配置了 NDK 环境变量就可以解决了。

  2. Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat// 由于 com.facebook.fresco:imagepipeline 模块引用了 support-v4.jar, // 如果项目中的其他模块也引用了 support-v4.jar, 那么需要去掉其中一个模块对 support-v4.jar 的引用 (exclude module: ''support-v4'') // 否则将会出现无法正确引用目标 support_v4.jar 的情况,或者报以下异常: //com.android.dex.DexException: // Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompatIcs;

compile (''com.facebook.fresco:fresco:0.4.0+'') {
    exclude module: ''support-v4''
}
  1. 自定义网络加载:OkHttp Image pipeline 默认使用 HttpURLConnection。应用可以根据自己需求使用不同的网络库。OkHttp 是一个流行的开源网络请求库。Image pipeline 有一个使用 OkHttp 替换掉了 Android 默认的网络请求的补充。如果需要使用 OkHttp, 不要使用这个下载页面的 gradle 依赖配置,应该使用下面的依赖配置
dependencies {
    // your project''s other dependencies
    compile ''com.facebook.fresco:drawee:0.4.0+''
    compile ''com.facebook.fresco:imagepipeline-okhttp:0.4.0+''
}

配置 Image pipeline 这时也有一些不同,不再使用 ImagePipelineConfig.newBuilder, 而是使用 OkHttpImagePipelineConfigFactory:

Context context;
OkHttpClient okHttpClient; // build on your own
ImagePipelineConfig config = OkHttpImagePipelineConfigFactory
    .newBuilder(context, okHttpClient)
    . // other setters
    . // setNetworkFetchProducer is already called for you
    .build();
Fresco.initialize(context, config);
  1. java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader [...] couldn''t find "libmemchunk.so"   64 位机器暂时还有问题:Fresco does not put any libraries in "lib/arm64", it will be fixed by #176 soon.(已解决)

  Working on version 0.5.1!

NoMethodError in SessionsController#create from a rails program

NoMethodError in SessionsController#create from a rails program

如何解决NoMethodError in SessionsController#create from a rails program?

有人能帮忙解决这个错误吗?

enter image description here

我正在尝试让用户能够使用谷歌身份验证登录>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

PHP date_create_from_format 使用对象给出 bool(false) 错误

PHP date_create_from_format 使用对象给出 bool(false) 错误

如果你想从两个日期计算天数

然后你可以使用

$ceated_date = "2021-2-27 10:05:00";

//create a date object of created date and get timestamp.
$t1 = (new DateTime($created_date))->getTimetamp();

//create a date object of now and get timestamp.
$t2 = (new DateTime("now"))->getTimestamp();

//this will give you days
$day_diff = floor(($t2 - $t1) / 86400);

Rails: Access to current_user from within a model in Ruby on Rails

Rails: Access to current_user from within a model in Ruby on Rails

问题:

I need to implement fine-grained access control in a Ruby on Rails app.我需要在 Ruby on Rails 应用程序中实现细粒度的访问控制。 The permissions for individual users are saved in a database table and I thought that it would be best to let the respective resource (ie the instance of a model) decide whether a certain user is allowed to read from or write to it.单个用户的权限保存在一个数据库表中,我认为最好让相应的资源(即模型的实例)决定是否允许某个用户读取或写入它。 Making this decision in the controller each time certainly wouldn''t be very DRY.每次在控制器中做出这个决定肯定不会很枯燥。
The problem is that in order to do this, the model needs access to the current user, to call something like may_read ?( current_user , attribute_name ) .问题是,为了做到这一点,模型需要访问当前用户,调用诸如may_read ?( current_user , attribute_name ) Models in general do not have access to session data, though.但是,模型通常无法访问会话数据。

There are quite some suggestions to save a reference to the current user in the current thread, eg in this blog post .有很多建议可以在当前线程中保存对当前用户的引用,例如在这篇博文中。 This would certainly solve the problem.这肯定能解决问题。

Neighboring Google results advised me to save a reference to the current user in the User class though, which I guess was thought up by someone whose application does not have to accommodate a lot of users at once.不过,邻近的 Google 结果建议我在 User 类中保存对当前用户的引用,我猜这是由其应用程序不必同时容纳大量用户的人想到的。 ;) ;)

Long story short, I get the feeling that my wish to access the current user (ie session data) from within a model comes from me doing it wrong .长话短说,我觉得我希望从模型中访问当前用户(即会话数据)是因为我做错了。

Can you tell me how I''m wrong?你能告诉我我是怎么错的吗?


解决方案:

参考: https://stackoom.com/en/question/6Zxq

今天关于rails resce_from 设置错误页面的讲解已经结束,谢谢您的阅读,如果想了解更多关于Error:(47, 13) Failed to resolve: com.facebook.fresco:fresco:0.11.0、NoMethodError in SessionsController#create from a rails program、PHP date_create_from_format 使用对象给出 bool(false) 错误、Rails: Access to current_user from within a model in Ruby on Rails的相关知识,请在本站搜索。

本文标签: