这与Trying扩展ActionView :: Helpers :: FormBuilder类似,但我不想使用:builder => MyThing.
我想扩展表单生成器以添加自定义方法.这是目前的情况:
module ActsAsTreeHelpers
def acts_as_tree_block(method, &block)
yield if block_given?
end
end
ActionView::Helpers::FormBuilder.send :include, ::ActsAsTreeHelpers
Run Code Online (Sandbox Code Playgroud)
安慰:
ruby-1.9.2-p180 :004 > ActionView::Helpers::FormBuilder.included_modules
=> [ActsAsTreeHelpers, ...]
Run Code Online (Sandbox Code Playgroud)
但以下给了我: undefined method acts_as_tree_block for #<ActionView::Helpers::FormBuilder:0xae114dc>
<%= form_for thing do |form| %>
<%= form.acts_as_tree_block :parent_id, {"test"} %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么?
我正在制作一个Android应用程序,它将一些下载的pdf文件存储在设备的SD卡中.一切正常,但现在我想添加一个功能,只需弹出默认的android文件/文件夹浏览器,显示我的应用程序存储所有PDF(包含子目录)的目录,以便用户可以看到他的文档存储位置和可以轻松浏览它们.
我经历了很多其他SO问题和论坛帖子,但似乎这只能用于音乐/图像/联系人等.基本上那些具有"专用浏览系统"但不具有一般文件浏览功能的文件类型.
我实际上是在使用这段代码:
File file = new File("/sdcard/MySorgenia/Documenti/");
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
Uri data = Uri.fromFile(file);
String type = "*/*";
intent.setDataAndType(data, type);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
但这将显示一个"选择应用程序以完成您的操作"对话框,其中包含许多应用程序,如"音乐""图库"等,但没有通用目的.
谢谢!
我在Windows 7笔记本电脑上有一个完美的开发环境.今天,我得到了一台新的Windows 8笔记本电脑,并尝试在其上设置开发环境.安装了rails等并创建了新的示例应用程序,它运行良好.然后我克隆了我的应用程序并尝试了.收到以下错误:
Completed 500 Internal Server Error in 2354ms
ActionView::Template::Error ((in C:/....../appname/app/assets/javascripts/gmaps4rails/gmaps4rails.base.js.coffee)):
3: <head>
4: <title><%=yield :title %></title>
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8: <%= render 'layouts/shim' %>
9: </head>
app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb__782381622_56858160'
Rendered C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.7/lib/action_dispa
Run Code Online (Sandbox Code Playgroud)
我用谷歌搜索并搜索了所有javascript_include_tag,并审查了许多线程,但无法找到解决方案.
感谢您解决此问题的任何帮助.
环境信息:
$rails -v
Rails 3.2.7
$ruby -v
ruby 1.9.3p327 (2012-11-10) [i386-mingw32]
Run Code Online (Sandbox Code Playgroud)
编辑:我刚刚注意到,当我有咖啡脚本文件甚至是空文件时,会出现此问题.我还是不知道如何解决它.
为了包含我在某些页面上只需要的一段javascript,我放了
= javascript_tag do
= render "inserts_js_enhanced_element.js.erb"
Run Code Online (Sandbox Code Playgroud)
在我的haml档案中.现在我在测试中收到警告:
DEPRECATION WARNING: Passing a template handler in the template name is
deprecated. You can simply remove the handler name or pass render
:handlers => [:erb] instead.`
Run Code Online (Sandbox Code Playgroud)
但是,当我将线路更改为
= render "inserts_js_enhanced_element.js", :handlers => [:erb]
Run Code Online (Sandbox Code Playgroud)
无论如何,我得到一个新的警告,说
DEPRECATION WARNING: Passing the format in the template name is
deprecated. Please pass render with :formats => [:js] instead.
Run Code Online (Sandbox Code Playgroud)
如果我确实改变了
= render "inserts_js_enhanced_element", :handlers => [:erb], :formats => [:js]
Run Code Online (Sandbox Code Playgroud)
它给了我错误
ActionView::Template::Error:
Missing partial application/inserts_js_enhanced_element with {:handlers=>[:haml, …Run Code Online (Sandbox Code Playgroud) 我正在尝试完成Michael Hartl的Ruby on Rails教程,我被困在第8章.我在运行测试时遇到了同样的两个错误:
NoMethodError:未定义的方法remember_token='
ActionView::Template::Error: undefined methodfind_by_remember_token'
我对编码和编程很陌生,所以我不确定要发布什么,所以人们可以帮我解决问题.我觉得我已经定义了:remember_token和find_by_remember_token.我已经包含了以下每个实例:remember_token出现在我的代码中:
sample_app/app/helpers/sessions_helper.rb:
2
3 def sign_in(user)
4: cookies.permanent[:remember_token] = user.remember_token
5 self.current_user = user
6 end
.
15
16 def current_user
17: @current_user ||= User.find_by_remember_token(cookies[:remember_token])
18 end
19
20 def sign_out
21 self.current_user = nil
22: cookies.delete(:remember_token)
23 end
24 end
sample_app/app/models/user.rb:
16
17 before_save { |user| user.email = email.downcase }
18: before_save :create_remember_token
19
20 validates :name, presence: true, length: { maximum: 50 }
..
27 private
28
29: …Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中创建了一个方法,将我的布局保存为图像并将其显示在库中.我正试图打开它,但我很难用所有的教程和不同的方法......
这是我的代码:
SimpleDateFormat mTimeFormat = new SimpleDateFormat("dd-MM-yyyy");
Date mTime = new Date();
String mStringTime = mTimeFormat.format(mTime);
String fileFolder = "/orders";
String fileName = "/order-"+mStringTime;
File filePath = new File("/sdcard"+fileFolder+fileName+".png");
Uri fileUri = Uri.fromFile(filePath);
File createFolder = new File(Environment.getExternalStorageDirectory()+fileFolder);
if (!createFolder.exists()){ //checks I don't create the same folder twice
createFolder.mkdir();
}
View orderView = findViewById(R.id.tableOrder); //this is what i shall save
orderView.setDrawingCacheEnabled(true);
Bitmap bitmap = orderView.getDrawingCache();
try {
FileOutputStream outputImage = new FileOutputStream(filePath);
bitmap.compress(CompressFormat.PNG, 10, outputImage);
outputImage.close();
orderView.invalidate();
Intent intentScanner = …Run Code Online (Sandbox Code Playgroud) 该form_with帮助器不会id为表单元素生成 s,因此也不会生成for属性。这与老form_tag和form_for帮手不同。
如果您想使用form_with而不是已弃用的form_tag和form_for帮助程序,但您希望id生成 s,则需要将其添加到您的配置中:
config.action_view.form_with_generates_ids = true
Run Code Online (Sandbox Code Playgroud)
id生成在某些情况下很有用,因为某些前端事物可能需要它。最重要的是,在我看来,不生成for属性意味着生成的表单form_with具有较少的 a11y。
我目前正在使用一个较旧的代码库,其中id需要表单元素,我的下意识反应是启用上述配置设置,这样我就可以使用而form_with无需为每个元素手动设置 ID。
默认form_with不生成的原因是什么?ids我担心我在这里遗漏了一些东西,因为我认为这个决定是有充分理由的。
我的布局中有一个子菜单,它与控制器不同,但不是每个控制器方法视图之间.我目前正在做的是以下内容:
<% content_for( :submenu ) do %>
<%= render :partial => 'submenus/correct_submenu' %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
在方法的每个视图中
我的应用程序布局就是这个
<%= yield :submenu %>
Run Code Online (Sandbox Code Playgroud)
然而,这对于每个视图都是重复的.有没有办法在每个控制器上执行此操作?
我正在寻找一些想法如何让星星在这个例子中看起来像:

现在,我有一张桌子上有一个黑色星柱和一个灰色星柱.(在"Hüllenkontrolle"中,例如2个黑色星的"2"和4个灰色星星的"4").所以我考虑了一些显示另一张图片的内容,具体取决于数据库中的数字(1 = 1星,2 = 2星,3 = 3星,4 = 4星...)
我不知道在互联网上搜索什么或者如何意识到不会看到数字而是一些明星.有谁知道如何实现这个?
有关我的数据库模型的一些信息:http://img6.imagebanana.com/img/kwenevyz/beziehungen.png
<%= expected_qualification.qualificationstars %> <% @employee.position.expected_qualifications.each do |expected_qualification| %>
<%= expected_qualification.qualificationstars %> <% @employee.position.expected_qualifications.each do |expected_qualification| %>
<% @employee.position.expected_qualifications.each do |expected_qualification| %>
<%= expected_qualification.qualificationstars %>
<%end%>
一些好消息!这似乎有效
<% @employee.position.skills.zip(@employee.position.expected_qualifications, @employee.current_qualifications).each do |skill, expected_qualification, current_qualification| %>
<p>
<% (current_qualification.istqualifikation).times do %>
<%= image_tag("black.png") %>
<% end %>
<% (expected_qualification.sollqualifikation - current_qualification.istqualifikation).times do %>
<%= image_tag("grey.png") %>
<% end %>
</p>
<% end %> …Run Code Online (Sandbox Code Playgroud) 嗨,我是Ruby on Rails的新手,我正在网上关注Michael Hartl的书.在局部模板他的书的部分.他用来渲染部分的代码是
<%= render 'layouts/stylesheets' %>
但是我得到了这个错误.
我读了API并尝试了这个
<%=render :partial => "/layouts/stylesheets" %>但仍然无法想象这一个.
感谢您的帮助!
render actionview partials missing-template ruby-on-rails-3.2
actionview ×10
android ×2
ruby ×2
formbuilder ×1
forms ×1
gallery ×1
image ×1
javascript ×1
methods ×1
partials ×1
render ×1
sd-card ×1
undefined ×1
windows-8 ×1