actionview

Rails 5: form_for vs form_with

烂漫一生 提交于 2021-02-08 12:33:30
问题 Rails 5 has introduced new form helper method form_with . How does it differs with form_for and when is it more appropriate to use? 回答1: This is really in preparation for rails 5.1 where only form_with should be used. It's meant to serve as a replacement for the two methods form_for and form_tag . form_for and form_tag in Rails were very similar, both allowed you to create a form tag but the first one uses model’s attributes to build create or update form, while the second one simply creates

Force android app to open when it's installation complete

只谈情不闲聊 提交于 2021-01-28 00:23:35
问题 I'm running an android app to be the only app to run on the system, so, when boot-completed I launch the app and prevent the user from exiting it for any reason(which made me disable both navigation status bars). Then, to achieve an update to the app, I look if there is a new one, and if so, I run a background task to download the new update from the sftp server using jsch, and when the app finish downloading, I install the apk using ACTION_VIEW intent: Intent intent = new Intent(Intent

How to fix this ActionView::Base depreciation with a lookup context?

给你一囗甜甜゛ 提交于 2021-01-27 12:13:11
问题 I migrate an application from rails 5.2 to rails 6. There is only have one thing left to do but I don't know how. I have this depreciation warning: DEPRECATION WARNING: ActionView::Base instances should be constructed with a lookup context, assignments, and a controller. (called from new at /Users/xxx/xxxx/app/models/stock.rb:42) from this code: view = ActionView::Base.with_empty_template_cache.new(ActionController::Base.view_paths, categories: categories, periods: periods) result = view

Android7.0适配SD卡权限

↘锁芯ラ 提交于 2021-01-10 10:57:04
之前APP中有一个功能,版本更新下载新的APK文件之后,直接打开系统的安装页面。原来的代码如下: private void install(File apkFile) { Uri uri = Uri.fromFile(apkFile); Intent localIntent = new Intent(Intent.ACTION_VIEW); localIntent.setDataAndType(uri, "application/vnd.android.package-archive"); startActivity(localIntent); } 以上的代码在7.0一下正常执行,但是运行在7.0以上的设备就会闪退。而7.0的” StrictMode API 政策” 禁止向你的应用外公开 file:// URI。 如果一项包含文件 file:// URI类型 的 Intent 离开你的应用,应用失败,并出现 FileUriExposedException 异常。解决办法如下: 在res目录下新建一个xml文件夹,并创建一个名为provider_paths.xml的文件 <?xml version="1.0" encoding="utf-8"?> <paths> <external-path name="external_path" path="."/> </paths>

android app通知栏权限状态判断及跳转状态栏设置页面

拟墨画扇 提交于 2020-11-03 07:56:42
import android.app.NotificationManager; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Build; import android.provider.Settings; import android.support.v4.app.NotificationManagerCompat; /** * Created by chenxiangxiang on 2019/1/16. */ public class Utils { public static boolean isPermissionOpen(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { return NotificationManagerCompat.from(context).getImportance() != NotificationManager.IMPORTANCE_NONE; } return NotificationManagerCompat.from(context).areNotificationsEnabled

android.os.FileUriExposedException:file:///storage/emulated/0/test.txt通过Intent.getData()在应用程序之外公开

血红的双手。 提交于 2020-08-12 02:11:53
问题: The app is crashing when I'm trying to open a file. 当我尝试打开文件时,应用程序崩溃。 It works below Android Nougat, but on Android Nougat it crashes. 它在Android Nougat以下运行,但是在Android Nougat上崩溃。 It only crashes when I try to open a file from the SD card, not from the system partition. 仅当我尝试从SD卡而不是系统分区打开文件时,它才会崩溃。 Some permission problem? 一些权限问题? Sample code: 样例代码: File file = new File("/storage/emulated/0/test.txt"); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "text/*"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); // Crashes on this

Android 调用第三方浏览器打开

匆匆过客 提交于 2020-08-09 15:00:26
/** * 调用第三方浏览器打开 * * @param context * @param url 要浏览的资源地址 */ public static void openBrowser(Context context, String url) { final Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); // 注意此处的判断intent.resolveActivity()可以返回显示该Intent的Activity对应的组件名 // 官方解释 : Name of the component implementing an activity that can display the intent if (intent.resolveActivity(context.getPackageManager()) != null) { final ComponentName componentName = intent.resolveActivity(context.getPackageManager()); // 打印Log ComponentName到底是什么 Log.d("componentName", "componentName =

ActionView::Template::Error: wrong number of arguments (Simple Form)

喜你入骨 提交于 2020-07-22 21:44:31
问题 I have a Rails 4 app that always worked, but now a page with a simple_form_for is generating an error. I dropped all the code, leaving just the simple_form_for and still yet I'm getting error. The page with errors (_form.html.erb): <%= simple_form_for @anuncio do |f| %> <%= f.input :titulo %> <% end %> When I execute this page, I get this error: F, [2015-01-08T16:16:21.920151 #19971] FATAL -- : ActionView::Template::Error (wrong number of arguments (3 for 2)): 1: <%= simple_form_for @anuncio

ActionView::Template::Error: wrong number of arguments (Simple Form)

岁酱吖の 提交于 2020-07-22 21:41:41
问题 I have a Rails 4 app that always worked, but now a page with a simple_form_for is generating an error. I dropped all the code, leaving just the simple_form_for and still yet I'm getting error. The page with errors (_form.html.erb): <%= simple_form_for @anuncio do |f| %> <%= f.input :titulo %> <% end %> When I execute this page, I get this error: F, [2015-01-08T16:16:21.920151 #19971] FATAL -- : ActionView::Template::Error (wrong number of arguments (3 for 2)): 1: <%= simple_form_for @anuncio

<%= with a block in rails 4

纵饮孤独 提交于 2020-07-03 09:39:48
问题 I'm trying to use a block in a helper, but that's giving me this error: SyntaxError - syntax error, unexpected ')' ...rbout.concat(( green_title do ).to_s); _erbout.concat "\n ... ... ^ (erb):4254: syntax error, unexpected end-of-input, expecting ')' ; _erbout.force_encoding(__ENCODING__) ^: (erb):1649:in `' here's how I'm calling it: <%= green_title do %> text <% end %> and here's my helper: def green_title(&block) capture do concat content_tag(:h3) do yeld end end end 回答1: Your block is