Tag: 的Ruby on 轨道

在Facebook页面上发布的简便方法(不是个人资料,而是粉丝页面)

哪个选项是在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 谢谢。

测试Web应用程序与Cucumber的Facebook集成

我想通过执行以下场景来使用Cucumber和Capybara来测试我的Rails应用程序的Facebook注册过程: @javascript Scenario: Connect account When I go to the home page And I press “Connect your Facebook account” And I fill in “test@address” for “Email” And I fill in “test” for “Password” And I press “Login” And I press “Allow” Then I should be on the dashboard page 人们如何解决基于浏览器的Facebook集成的集成测试问题? 网络搜索只显示了几个早于图API的博客文章,他们似乎只讨论实现一个前提条件,即设置一个代表已登录到Facebook的用户的环境。 要解决的一些具体问题: 如何模拟单击元素? 我想出的最好的事情(但尚未测试)是手动触发元素上的click事件。 一旦Facebook对话框出现,Capybara可以访问它吗? […]

如何在rails视图中访问javascript变量

有没有办法在rails视图中访问javasript变量。 我只是设置了javascript变量的一些值,并希望在rails视图中访问它。 谢谢

rails fields_for在嵌套表单上的validation错误后不呈现

我有一个嵌套的表单问题。 我实现了railscasts 196和197的嵌套表单解决方案。如果我没有validation错误,它就可以工作。 因此,表单在加载时会完美呈现,包括嵌套字段(在fields_for部分中)。 但是,表格有validation。 validation失败时,控制器会渲染:new。 然后表单呈现链接的模型字段,但不再渲染嵌套字段。 这有解决方案吗? 控制器 def new @property = Property.new @property.images.build end def create @property = Property.new(params[:property]) if @property.save flash[:success] = t(‘Your_property’) + ‘ ‘ + t(‘is_successfully_created’) redirect_to myimmonatie_url else render :action => ‘new’ end end 部分观点: { :action => “create” }, :html => { :multipart => true } do |f| […]

从有关rails图表api的post中删除“通过APP_NAME”

目前,我正在使用RestClient向朋友的时间线发布简单的post。 RestClient.post ‘https://graph.facebook.com/_friend_/feed’, :access_token => “_token_”, :message => “_message_” 这样可行,但当它显示在我朋友的时间轴上时,post底部会显示“通过APP_NAME”的文字。 有没有办法摆脱它?

Rails:如何在内部POST到另一个控制器动作?

这听起来很奇怪,但是听我说……我需要能够向我的其他控制器发出相应的POST请求。 SimpleController基本上是更详细的控制器的简化版本。 我怎么能这样做呢? class VerboseController < ApplicationController def create # lots of required params end end class SimpleController < ApplicationController def create # prepare the params required for VerboseController.create # now call the VerboseController.create with the new params end end 也许我过度思考这个问题,但我不知道该怎么做。

客户端未经授权使用此方法检索访问令牌

我在Ruby on Rails项目中有一个自定义仪表板,其中包含从Google Analytics收集的数据。 我使用Google Analytics Reporting V4 API和服务帐户进行身份validation。 如果我没有模仿用户authorization.sub = ‘xxx@mail.com’ ,我的代码运行良好。如果我这样做,我会收到unauthorized_client错误,但不是所有时间。 有时它有效,有时不行。 这是我的代码: scope = [Google::Apis::AnalyticsreportingV4::AUTH_ANALYTICS_READONLY] view_id = ‘xxxxxx’ ENV[‘GOOGLE_APPLICATION_CREDENTIALS’] = “#{Rails.root}/private/google_analytics_key.json” authorization = Google::Auth::get_application_default(scope) authorization.sub = ‘xxx@mail.com’ analytics = Google::Apis::AnalyticsreportingV4::AnalyticsReportingService.new analytics.authorization = authorization … request = Google::Apis::AnalyticsreportingV4::GetReportsRequest.new(report_requests: report_requests) @result = analytics.batch_get_reports(request) Rails服务器日志输出: Sending HTTP post https://analyticsreporting.googleapis.com/v4/reports:batchGet? Caught error Authorization failed. Server message: […]

如何覆盖rails模型的“new”方法

在我的rails应用程序中,我有一个带有start_date和end_date的模型。 如果用户选择2010年1月1日作为start_date和2010年1月5日作为end_date,我希望创建5个模型实例(每天选择一个)。 所以它看起来像 Jan 1, 2010 Jan 2, 2010 Jan 3, 2010 Jan 4, 2010 Jan 5, 2010 我知道处理这个问题的一种方法是在控制器中进行循环。 就像是… # …inside controller start_date.upto(end_date) { my_model.new(params[:my_model]) } 但是,我想保持我的控制器瘦,加上我想保持模型逻辑不在其中。 我猜我需要覆盖模型中的“新”方法。 最好的方法是什么?

如何在Rails应用程序中设置组合键

我在我的应用程序中使用’foriegner’gem来设置主键,现在我处于在表中设置复合主键的情况。 我在网上搜索了这个,但无法为此找到明确的解决方案。 如果可以使用foreigner gem或任何其他方法在rails应用程序中设置复合键,请建议我。 注意:我使用的是Postgres 谢谢。

让offline_access与Facebook合作

我正在使用Facebooker和Rails将我的应用程序连接到Facebook。 我可以指导用户完成授权过程,并通过授予我的应用程序离线访问权限的过程。 我如何实际离线访问信息? 有没有办法请求一个不会过期的session_key,我可以在以后使用,只要用户没有撤​​销我在Facebook上的应用程序的权限? 任何帮助非常感谢。 建议不必特定于轨道。