哪个选项是在Facebook页面上发布文本或其他内容的最佳和最简单的方法?
我正在寻找一种从我的Rails应用程序中放置一些东西的直接方法.
例如,单击按钮并自动在我的应用程序上发布并将数据发送到Facebook页面?
我已经为Twitter构建了一个,我的方法看起来像这样:
def tweet(url)
Twitter.configure do |config|
config.consumer_key = APP_CONFIG['twitter_consumer_key']
config.consumer_secret = APP_CONFIG['twitter_consumer_secret']
config.oauth_token = APP_CONFIG['twitter_access_token']
config.oauth_token_secret = APP_CONFIG['twitter_secret_token']
end
shorted_url = shorten_url(url)
Twitter.update("#{title} - #{shorted_url}")
end
Run Code Online (Sandbox Code Playgroud)
谢谢.
HTML:
<p class="fields">
<select id="parts">
<option value="10">Ring</option>
<option value="50">Necklace</option>
<option value="3">Pendant</option>
</select>
<label for="price">Price</label>
<span class="price"></span>
</p>
function load_part_price_select(id, value) {
$('#' + id ).live('change',function() {
$.ajax({
url: '/parts/' + value + '/price',
type: 'get',
context: this,
dataType: 'script',
success: function(responseData) {
$(this).next("span.price").html(responseData);
}
});
});
};
Run Code Online (Sandbox Code Playgroud)
我试过这种方式却没有成功.
"onchange"工作正常我只需要一些帮助就可以将span标记内的值显示为内容.
有帮助吗?
我用rmagick安装了carrierwave gem.
如果加载WEBrick但在尝试使用nginx时获得500内部服务器错误,我可以正常工作.
nginx error.log说:
2011/08/14 10:06:40 [crit] 760#0: *4247 open() "/usr/local/Cellar/nginx/1.0.4/client_body_temp/0000000033" failed (13: Permission denied), client: 127.0.0.1, server: jewellery.dev, request: "POST /items/28?locale=en HTTP/1.1", host: "jewellery.dev:8080", referrer: "http://jewellery.dev:8080/items/28/edit?locale=en"
Run Code Online (Sandbox Code Playgroud)
我还在initializers文件夹上创建了一个文件,其中包含:
CarrierWave.configure do |config|
config.permissions = 0777
end
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
我想为我的应用程序创建一些测试,我有以下错误:
1) User feeds ordering should order feeds by id desc
Failure/Error: @post_1 = FactoryGirl.create(:post)
ActiveRecord::AssociationTypeMismatch:
Attachment(#87413420) expected, got Rack::Test::UploadedFile(#81956820)
# ./spec/models/user_spec.rb:37:in `block (3 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)
这个错误是因为我的factories.rb文件中有这个
factory :post do
title "Lorem Ipsum"
description "Some random text goes here"
price "500000"
model "S 403"
makes "Toyota"
prefecture "Aichi-ken"
contact_info "ryu ryusaki"
year "2012"
shaken_validation "dec/2014"
attachments [ Rack::Test::UploadedFile.new(Rails.root.join("spec/fixtures/files/example.jpg"), "image/jpeg") ]
#attachments [ File.open(Rails.root.join("spec/fixtures/files/example.jpg")) ]
end
Run Code Online (Sandbox Code Playgroud)
测试期望一个Attachment对象,但我正在创建一个Rack::Test::UploadedFile对象.我该如何解决这个错误?
谢谢.
我正在使用nested_attributes并尝试在Ryan Bates关于嵌套模型的屏幕录像(#196)之后实时添加/删除字段ajax
这样做,它将无法工作,但删除"link_to_add_fields"行时,它可以正常工作.
问题是,我不知道我是否正确地做了这一切.
<%= form_for(@item) do |f| %>
<% if @item.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@item.errors.count, "error") %> prohibited this item from being saved:</h2>
<ul>
<% @item.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :item_type_id %><br />
<%= f.select :item_type_id, @item_types.collect { |p| [ p.title, p.id ]} %>
<br />
<%= f.fields_for :item_parts do |parts_form| %> …Run Code Online (Sandbox Code Playgroud) 可能重复:
jQuery返回ID以某个字符串开头的元素
好的,我想说我有以下几个要素:
<select id="state_id" value="20">test1</select>
<select id="state_id1" value="21">test2</select>
<select id="state_id2" value="22">test3</select>
Run Code Online (Sandbox Code Playgroud)
在这种情况下length(),如何获取id开头的select标签state_id?
我试过了,$("^#state_id").length();但没有成功.
任何提示?
class Post
def save
Mailer.notify!('bla')
true
end
end
Run Code Online (Sandbox Code Playgroud)
如何测试何时post.save被调用,该Mailer.notify方法被触发?并有正确的论据。
使用 RSpec 我通常会这样做:
expect(Mailer).to receive(:notify!).with('bla')
post.save
Run Code Online (Sandbox Code Playgroud)
先感谢您!
我试图从我的博客加载提要但这导致提到的标题中的错误.
错误消息:
NoMethodError (undefined method `entries' for 0:Fixnum):
app/controllers/pages_controller.rb:6:in `home'
Run Code Online (Sandbox Code Playgroud)
这就是我在做的事情:
我在名为的文件lib夹中创建了一个文件blog_feeds.rb,其中仅包含以下内容:
module BlogFeeds
require 'feedzirra'
def load_feeds
feeds = Feedzirra::Feed.fetch_and_parse('http://blog.shigotodoko.com/feed')
end
end
Run Code Online (Sandbox Code Playgroud)
错误的第6行是:
@feeds = load_feeds.entries
Run Code Online (Sandbox Code Playgroud)
请注意,此错误有时仅发生,而不是总是发生.
那么,关于这里出了什么问题的任何想法?
谢谢!
具有以下结构:
<td class="padding_right padding_left">Neighborhood</td>
<td>
<div id="neighborhoods_region">
<select class="inputs_form_data" id="neighborhood_id2" name="neighborhood_id2">
<option value=""></option>
<option value=""></option>
</select>
</div>
</td>
<td width="10%"><a class='delete-region'>remover</a></td>?
Run Code Online (Sandbox Code Playgroud)
我正在尝试remove点击链接,以获取选择ID的ID号.在这种情况下,我需要从"neighborhood_id2"中获取数字2.
但首先我只是想获得完整的身份证.neighborhood_id2使用以下代码:
$(document.body).on('click','a.delete-region', function () {
alert($(this).closest('select').attr("id"));
});
Run Code Online (Sandbox Code Playgroud)
但这会让我回报undefined.
注意:该id号码是在动态表单上即时生成的.所以我可能有neighborhood_id3,等等.
给出以下辅助方法.
def link_tags(collection)
tags = collection.split(',')
tags.map.each do |tag|
if tag == tags.last
content_tag(:a, tag, href: tags_filter_post_path(tag) )
else
content_tag(:a, tag, href: tags_filter_post_path(tag) ) + ', '
end
end.reduce(:<<)
end
Run Code Online (Sandbox Code Playgroud)
我怎么能对此做一点重构?
编辑:重构后的最终代码建议.
def link_tags(collection)
collection.split(',').collect do |tag|
link = ""
link += link_to tag, tags_filter_post_path(tag)
end.join(', ').html_safe
end
Run Code Online (Sandbox Code Playgroud) 我根据我发现的代码示例尝试以下内容:
echo "file.txt" | awk '{split($0,a,"."); print a[0]}'
Run Code Online (Sandbox Code Playgroud)
但它返回一个空白输出.
任何提示?
可能重复:
如何在Javascript中合并两个数组
假设我有2个数组:
a = ['a','b','c'];
b = ['d','e','f'];
Run Code Online (Sandbox Code Playgroud)
有什么方法可以轻松添加b到a无需拆分和执行each添加元素?
就像是:
a.push(b);
Run Code Online (Sandbox Code Playgroud)
并有一个a内容的最终数组:
a = ['a','b','c','d','e','f']
Run Code Online (Sandbox Code Playgroud) jquery ×4
javascript ×3
ruby ×2
arrays ×1
associations ×1
awk ×1
bash ×1
carrierwave ×1
facebook ×1
factory-bot ×1
feeds ×1
feedzirra ×1
gem ×1
minitest ×1
nested-forms ×1
nginx ×1
parsing ×1
refactoring ×1
rspec2 ×1
rubygems ×1
shell ×1
split ×1
unit-testing ×1