这是代码
protected static final String DIR_IMAGE = "/data/data/it.android.myprogram/images/";
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
Uri u = Uri.fromFile(destinationFile);
intent.setDataAndType(u, "image/*");
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
如果我这样做,要打开的文件是/data/data/it.android.myprogram/images:
File dir = new File(DIR_IMAGE);
String[] files = dir.list();
Run Code Online (Sandbox Code Playgroud)
var文件包含所有文件,但是当我开始时
intent.setDataAndType(u, "image/*");
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
它显示了无法找到的信息/data/data/it.android.myprogram/images/img1.jpg
为什么?
我正在使用Rails 3.1,似乎我在我的create_error.js.coffee视图文件中的CoffeeScript语句之后无法使用Ruby脚本来获取AJAX响应.
如果我这样做它会起作用:
<% if @attached_image.errors.any? %>
alert 'something is wrong'
<% end %>
Run Code Online (Sandbox Code Playgroud)
但如果它如下所示,<% %>在CoffeeScript语句之后,
errors_block = '<div id="errors_block"></div>'
<% if @attached_image.errors.any? %>
something..
<% end %>
Run Code Online (Sandbox Code Playgroud)
我总是支持得到一个异常ActionView::Template::Error (Parse error on line 6: Unexpected 'INDENT')的if线.我已经尝试了几个样本,每当它发生<% %>在一个coffeescript声明之后的红宝石时.
这是为什么?
1进行申请,到目前为止一切正常.然而,无处不在,ActionView突然失败了.它似乎无法识别任何已关闭的HTML标签.每当它看到一个封闭的括号时,它声称这些是未公开的.但是,他们都是!我已经在下面发布了错误日志,也许有人知道发生了什么.我也只放了部分日志,因为它太大了.
~/app/views/layouts/application.html.erb:20: unknown regexp options - pa
unmatched close parenthesis: /div>
<div class="rhm1-bg">
Extracted source (around line #20):
17: <ul>
18: <% if user_signed_in? %>
19: Signed in as <%= current_user.email %>. Not you?
20: <li><span><%= link_to "Sign out", destroy_user_session_path, :method => :delete %></span></li>
21: <% else %>
22: <li><span><%= link_to "Sign up", new_user_registration_path %></span></li>
23: <li><span><%= link_to "Sign in", new_user_session_path %></span></li>
Run Code Online (Sandbox Code Playgroud)
但是在我的HTML文件中,这个div当然是关闭的.
编辑:似乎ActionView几乎失败了.任何人都知道为什么会突然发生这种情况?
当我启动应用程序崩溃后出现错误
/home/stereodenis/.rvm/gems/ruby-1.9.3-p194@nyanya/gems/haml-3.1.6/lib/haml/helpers/action_view_mods.rb:15:in `alias_method': undefined method `render' for class `ActionView::Base' (NameError)
Run Code Online (Sandbox Code Playgroud)
可能有什么不对?
以下代码返回一个people.csv文件而不是呈现文本.如果我没有使用respond_to块并只是渲染文本,浏览器将按预期工作.是什么迫使浏览器在文件中发送数据?正如预期的那样,mime-type是'text/csv'.
# /app/controllers/people_controller.rb
class PeopleController < ApplicationController
def index
respond_to do |format|
format.csv { render text: "Hello, world" }
end
end
end
Run Code Online (Sandbox Code Playgroud)
推论:渲染xls,这是一个正确注册的mime类型,模板强制渲染application.html,这看起来很奇怪.
# /app/controllers/people_controller.rb
class PeopleController < ApplicationController
def index
respond_to do |format|
format.xls
end
end
end
Run Code Online (Sandbox Code Playgroud)
.
# /app/views/people/index.xls.erb
<table border="1">
<tr>
<th>ID</th>
<th>Name</th>
</tr>
<% @people.each do |person| %>
<tr>
<td><%= person.id %></td>
<td><%= person.name %></td>
</tr>
<% end %>
</table>
Run Code Online (Sandbox Code Playgroud) 我一直在使用Action_View,以install apk使用下面的代码
Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
intent.setDataAndType(Uri.fromFile(new File(location + "myAPK.apk")),
"application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
它会在设备中打开“安装提示”窗口。现在用户可以安装或取消安装过程。
我只对当用户单击安装包但由于某种原因安装失败可能是损坏的 apk 或不匹配的签名 apk 等时感兴趣。
安装失败时如何捕获事件.. 我可以从 ACTION_INSTALL_PACKAGE
我已经阅读过,System Broadcast Messages但所有内容都用于添加或替换 Pacakge。
任何线索?
所以我使用form_with,我的代码放在views/users/new.html.erb
<% content_for :title, "Sign Up" %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2>
<%= pluralize(@user.errors.count, "error") %>
prohibited this user from being saved:
</h2>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= form_with model: @user do |f| %>
<%= f.label :email %>
<%= f.email_field :email, :placeholder => 'E-mail address' %><br>
<%= f.label :password %>
<%= f.password_field :password, :placeholder => 'Password' %>
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation, :placeholder …Run Code Online (Sandbox Code Playgroud) 我刚刚升级到Webpacker 6.0.0.beta.5,就出现了这个错误。
ActionView::Template::Error (undefined method `javascript_packs_with_chunks_tag' for #<ActionView::Base:0x0000000000fcf8>
Run Code Online (Sandbox Code Playgroud) 我的销毁链接不起作用.
我的索引视图:
<div id="konkurrancer"><%= render 'konkurrencer', :remote => true %></div><%= debug(params) %>
Run Code Online (Sandbox Code Playgroud)
我的发生部分:
<% for konkurrancer in @konkurrancers %> <%= link_to 'Destroy', [:admin, konkurrancer], :method => :delete %> <% end %>
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
No route matches {:action=>"show", :controller=>"admin/konkurrancers", :id=>#<Konkurrancer id: 41, name: " Vind 16.000 kr., til Bilka, Føtex eller Netto
Run Code Online (Sandbox Code Playgroud)
编辑错误查看:
ActionController::RoutingError in Admin/konkurrancers#index
Showing C:/Rails/konkurranceportalen/app/views/admin/konkurrancers/_konkurrencer.html.erb where line #59 raised:
No route matches {:action=>"show", :controller=>"admin/konkurrancers", :id=>#<Konkurrancer id: 41, name: " Vind 16.000 kr., til Bilka, Føtex eller Netto", banner1: "http://partner.smartresponse-media.com/42/1092/1210...", …Run Code Online (Sandbox Code Playgroud) 如何在Rails中捕获ActionView :: MissingTemplate错误?
例如,我PeopleController有一个Index方法,但它不需要模板.当有人浏览root_url/people时,他们会获得默认的静态错误模板.
而且这不是唯一有问题的控制器; 我希望所有丢失的模板错误将用户重定向到我的自定义视图.
Rails版本 - 3.0.19
提前致谢!
actionview ×10
android ×2
ruby ×2
alias-method ×1
coffeescript ×1
csv ×1
erb ×1
forms ×1
haml ×1
java ×1
mime-types ×1
render ×1
webpack ×1
webpacker ×1