我在Rails 3.1.1,Ruby 1.9.2和最新的gem(从github中提取).
将资源添加到Ruby的优秀ActiveAdmin gem中非常容易.我可以看到您还可以通过从app/admin中删除相关的.rb文件来删除资源.
我在文档中找不到任何关于它的内容,但有没有人知道是否有另一种方法删除资源...或者正确删除ActiveAdmin资源文件?
我已经构建了一些代码来对索引页面进行排序,在我的视图中使用链接.这适用于链接,工作代码是这样的:
<p>
<%= link_to "Sentence", :controller => params[:controller], :action => params[:action], :type => '1', :class => "btn" %>
<%= link_to "Question", :controller => params[:controller], :action => params[:action], :type => '2', :class => "btn" %>
<%= link_to "Mnemonic", :controller => params[:controller], :action => params[:action], :type => '3', :class => "btn" %>
<%= link_to "Article", :controller => params[:controller], :action => params[:action], :type => '4', :class => "btn" %>
<%= link_to "Recommendation", :controller => params[:controller], :action => params[:action], :type => '5', :class => …Run Code Online (Sandbox Code Playgroud) 我有一个Rails应用程序,并且暴露了一个由Angular前端使用的API.我使用will-paginate gem来分页我的大数据集.宝石期望:页面通过参数传递.
页面上的按钮工作正常,并调用nextPage或prevPage函数,但由于某种原因,具有页码的参数没有传递给Rails控制器.
当用户按下下一个或上一个按钮时,我希望从轨道控制器传送数据并在屏幕上刷新.
相关问题:Rails将使用angular.js来拼写gem以进行分页
应用程序/控制器/ API/data_sources_controller.rb
class Api::DataSourcesController < Api::BaseController
def index
Rails.logger.debug("index: datasources, page: #{params[:page]}")
render json: Cosmic.paginate(:page => params[:page], :per_page => 50)
end
end
Run Code Online (Sandbox Code Playgroud)
应用程序/资产/ Javascript角/控制器/ DatasetController.js.coffee
angular.module('assaypipelineApp').controller "DatasetController", ($scope, $routeParams, $location, DataSet) ->
$scope.currentPage = 1
$scope.init = ->
@panel_id = $routeParams.panel_id
console.log("dataset init: #{@panel_id}")
@datasetsService = new DataSet(serverErrorHandler)
$scope.datasets = @datasetsService.all({page: $scope.currentPage})
# pagination
$scope.prevPage = ->
console.log("prev #{$scope.currentPage}")
$scope.currentPage-- if $scope.currentPage > 0
$scope.datasets = @datasetsService.all({page: …Run Code Online (Sandbox Code Playgroud) 在github上的simple_form示例repo中,有一个包含包装器信息的块. https://github.com/rafaelfranca/simple_form-bootstrap/blob/master/app/views/examples/_horizontal_form_sf.html.erb
它工作正常,但似乎需要为每个表单添加许多额外的设置.有没有办法添加名称此信息并将其添加为参数?
<%= simple_form_for @user_horizontal, url: create_horizontal_examples_url, as: 'user_horizontal', html: { class: 'form-horizontal' },
wrapper: :horizontal_form,
wrapper_mappings: {
check_boxes: :horizontal_radio_and_checkboxes,
radio_buttons: :horizontal_radio_and_checkboxes,
file: :horizontal_file_input,
boolean: :horizontal_boolean
} do |f| %>
<%= f.error_notification %>
<%= f.input :email, placeholder: 'Email' %>
Run Code Online (Sandbox Code Playgroud) 我正在使用Cocoon gem在Rails中构建嵌套表单.此gem为每个重复的表单元素分配一个随机数,以便区分它们.
例如:
id="challenge_events_attributes_1464333427019_event_time_3i"
Run Code Online (Sandbox Code Playgroud)
其中'1464333427019'是随机数.
我尝试了各种迭代:
x = page.all(:xpath, '//input[contains("challenges_events_attributes")]')
puts "X: #{x.inspect}"
Run Code Online (Sandbox Code Playgroud)
假设我在页面上有多个元素,我如何使用Capybara(可能使用xpath)来定位这些元素,然后为它们赋值?
我对ReactJS,JavaScript和整个编码事物都很陌生.
我已经创建了一个从父组件传递给子组件的数组列表,现在我想创建一个onClick事件,每当用户单击任何该列表项时.
该值(用作键ID)将发送回父级,因此父级可以将该键值发送给另一个子级,该子级将使用基于要呈现的组件的键的条件呈现.我最好不要使用像flux这样的任何其他库.
我尽可能地陷入困境;将这个值从孩子传回父母.我认为语法有些混乱,或者我的逻辑可能不正确.我只能将它绑定到子类中的函数以检查是否正在注册该单击.
class Parent extends React.Component {
render() {
var rows = [];
this.props.listlinkarray.forEach(function(linklist) {
rows.push(<Child linklist={linklist} key={linklist.key} />);
});
return (
<div>
<h3> ListHead </h3>
{rows}
</div>
);
}}
class Child extends React.Component {
// was checking how the Onclick event works //
getComponent(data,event) {
console.log('li item clicked!');
console.log(data);
event.currentTarget.style.backgroundColor = '#ccc';
}
render() {
return (
<div>
<ul><li onClick={this.getComponent.bind(this,this.props.linklist.key)}>
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
Array有这些数据
var ListNameAndLinks= [
{ name:'ABC', key:1} ,
{ name:'BCD', key:2}
];
Run Code Online (Sandbox Code Playgroud)
我想根据点击到这个类传递父亲从子节点获取的值,以便它可以根据它获得的值进行渲染. …
我正在使用capistrano部署到VPS,基于RailsCasts的指南. http://railscasts.com/episodes/335-deploying-to-a-vps?view=asciicast
它在deploy:cold命令失败,与Ruby发生冲突.我实际上看不出问题是什么,因为当我对同一个用户进行shell时,Ruby版本看起来是正确的.
$ cap shell
cap> which ruby
[establishing connection(s) to 192.xxx.xxx.xxx]
** [out :: 192.xxx.xxx.xxx] /home/deployer/.rbenv/shims/ruby
cap> ruby -v
** [out :: 192.xxx.xxx.xxx ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux]
Run Code Online (Sandbox Code Playgroud)
这是错误:
command finished in 655ms
* 2013-07-01 16:40:39 executing `bundle:install'
* executing "cd /home/deployer/rails/assay/releases/20130701144038 && bundle install -- gemfile /home/deployer/rails/assay/releases/20130701144038/Gemfile --path /home/deployer/rails/assay/shared/bundle --deployment --quiet --without development test"
servers: ["192.xxx.xxx.xxx"]
[192.xxx.xxx.xxx] executing command
** [out :: 192.xxx.xxx.xxx] rbenv: version `1.9.3' is not installed
command finished in 662ms
*** …Run Code Online (Sandbox Code Playgroud) 我正在构建VPS,它通过Capistrano部署,数据库连接等,但页面没有可用的资源 - 它只是基本的html.
资产似乎已编译,并存在于共享目录中.
从页面html:
<link href="/assets/application-a1b5d69aeaff709fd3dce163c559b38b.css" media="all" rel="stylesheet" type="text/css" />
<script src="/assets/application-0ebd07089629f8c6880dddfb688d525d.js" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)
资产文件似乎存在于共享目录中:
assay@assaypipeline:~/apps/assay/shared/assets$ ls application- a1b5d69aeaff709fd3dce163c559b38b.css
application-a1b5d69aeaff709fd3dce163c559b38b.css
Run Code Online (Sandbox Code Playgroud)
当我查看,源,然后单击指向资产路径的超链接时,我从Nginx中找不到404.
解
感谢Martin M(接受了答复)的帮助.我从服务器上的〜/ apps /(app name)/ current目录中采取的步骤.
$ bundle install
$ RAILS_ENV=production bundle exec rake assets:precompile
$ sudo service nginx restart
Run Code Online (Sandbox Code Playgroud)
显然,将它包含在Capistrano配方中会更好.
*编辑 - Capfile*
load 'deploy'
load 'deploy/assets'
load 'config/deploy'
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Textacy计算标准语料库中单个单词的 TF-IDF 分数,但我对收到的结果有点不清楚。
我期待一个代表词在语料库中的频率的浮点数。那么为什么我会收到 7 个结果的列表 (?)?
“acculer”实际上是一个法语单词,因此期望从英语语料库中得到 0 的结果。
word = 'acculer'
vectorizer = textacy.Vectorizer(tf_type='linear', apply_idf=True, idf_type='smooth')
tf_idf = vectorizer.fit_transform(word)
logger.info("tf_idf:")
logger.info(tfidf)
Run Code Online (Sandbox Code Playgroud)
输出
tf_idf:
(0, 0) 2.386294361119891
(1, 1) 1.9808292530117262
(2, 1) 1.9808292530117262
(3, 5) 2.386294361119891
(4, 3) 2.386294361119891
(5, 2) 2.386294361119891
(6, 4) 2.386294361119891
Run Code Online (Sandbox Code Playgroud)
问题的第二部分是如何将我自己的语料库提供给 Textacy 中的 TF-IDF 函数,尤其是。一种不同的语言?
编辑
正如@Vishal 所提到的,我已经使用这一行记录了输出:
logger.info(vectorizer.vocabulary_terms)
Run Code Online (Sandbox Code Playgroud)
似乎提供的单词acculer已被拆分为字符。
{'a': 0, 'c': 1, 'u': 5, 'l': 3, 'e': 2, 'r': 4}
Run Code Online (Sandbox Code Playgroud)
(1)如何针对语料库获取这个词的TF-IDF,而不是每个字符?
(2) 如何提供自己的语料库并将其作为参数指向?
(3)TF-IDF可以在句子层面使用吗?即:这句话的术语相对于语料库的相对频率是多少。
我在后台作业中使用 Rails 和 Carrierwave 将许多小文件上传到 S3,并且达到了 S3 速率限制。我的直接想法是在每次上传之前添加一个sleep 0.1,但这似乎不是一个很好的解决方案。
关于如何通过 S3 API 和某种类型的退避处理这个问题有什么建议吗?
正在执行上传的 Ruby 代码,该方法在循环中被调用数千次:
def attach_audio(object:, audio_field:, attachment:)
return true if Rails.env.test?
language_code, voice_id = language_and_voice(object)
resp = polly.synthesize_speech(
output_format: 'mp3',
voice_id: voice_id,
text: audio_field.to_s,
language_code: language_code
)
audio_filename = "#{object.class.to_s.downcase}_#{attachment}_#{object.id}_#{voice_id}.mp3"
audio_path = "#{Rails.root}/db/audio/#{audio_filename}"
IO.copy_stream(resp.audio_stream, audio_path)
object.send(attachment + '=', Pathname.new(audio_path).open)
object.save!
end
Run Code Online (Sandbox Code Playgroud)
上传者类
class AudioUploader < BaseUploader
def store_dir
"uploads/audio/#{model.target_language}/#{self.class.to_s.underscore}/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_whitelist
%w[mp3]
end
end
Run Code Online (Sandbox Code Playgroud)
class BaseUploader < CarrierWave::Uploader::Base
if Rails.env.test?
storage :file
else
storage …Run Code Online (Sandbox Code Playgroud) capistrano ×2
activeadmin ×1
amazon-s3 ×1
angularjs ×1
capybara ×1
coffeescript ×1
nginx ×1
nlp ×1
python ×1
reactjs ×1
simple-form ×1
spacy ×1
textacy ×1
xpath ×1