我正在关注设置Puma并输入此命令的Heroku文档:
bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}
Run Code Online (Sandbox Code Playgroud)
这使我现在每次运行时都在我的开发环境中运行puma rails s.但是,或者Puma导致havok的任何原因.如何切换回使用WEBrick?
试着
bundle exec webrick -p ${PORT:-3000} -e ${RACK_ENV:-development}
Run Code Online (Sandbox Code Playgroud)
但当然,找不到命令:webrick.知道'太容易了......
谢谢!
我正在使用Rails基于一组复杂的嵌套属性自动神奇地创建子对象.因此,我需要以非常特殊的方式嵌套参数.显然我意识到我可以用JS构建它们,但是我希望表单的顺序自动帮助构造.对于上下文,我有2列,由2 <td>秒表示.每列可以创建新记录或编辑现有记录.当然,当要修改现有记录时,必须传递记录的id.
呈现的HTML如下:
<td width="50%" style="padding-right:3%" class="logistic-details" data-type="logistics" data-typelogistics="delivery" data-instructions="test instructions" data-id="1" data-amount="20">
<span class="area-to-inject-amount-inputs" data-object="type_logistics" data-type="logistics" data-typelogistics="delivery">
<input class="labeler-response" name="type_logistics_attributes[][id]" type="hidden" value="1">
<input class="labeler-response" name="type_logistics_attributes[][instructions]" type="text" value="test instructions">
</span>
</td>
<td width="50%" style="padding-right:3%" class="logistic-details" data-type="logistics" data-typelogistics="pickup" data-instructions="" data-id="" data-amount="0">
<span class="area-to-inject-amount-inputs" data-object="type_logistics" data-type="logistics" data-typelogistics="pickup" data-actioned="charged">
<input type="hidden" name="type_logistics_attributes[][type_of_logistics]" value="pickup">
<input class="injected-amount-input" type="number" min="0" max="" placeholder="Amount" name="type_logistics_attributes[][charged_amounts_attributes][][amount]" value="20">
<span class="area-to-inject-type-of-amount">
<input type="hidden" name="type_logistics_attributes[][charged_amounts_attributes][][type_of_amount]" value="logistics">
</span>
<input class="labeler-response" name="type_logistics_attributes[][instructions]" type="text" placeholder="Enter address and instructions">
</span>
</td>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,第一个<td>是修改id为1的现有记录,而第二个<td> …
html ruby-on-rails named-parameters nested-forms nested-attributes
我项目的原始,愉快工作版本看起来像这样:
1)用户填写表格(新动作)并点击提交(创建动作)
2)用户被重定向到他们的编辑页面(编辑操作使用由模型创建的edit_id,而不是Rails自动生成ID),这显示用户已经提交的信息
3)用户可以选择更改信息(更新操作)并重新提交
在此版本中,即使用户在编辑页面中未进行任何更改并提交,该页面仍将闪烁成功警报.
从数据库的角度来看,我并不在意,因为表单预先填充了用户的信息,update_attributes方法只是用相同的信息覆盖旧信息.
从用户的角度来看,它很烦人,所以我想确保只更新信息,并且只有当用户实际更改某些内容时才会闪烁成功警报.
我认为这很容易,改变旧的代码:
def update
@request = Request.find_by_edit_id(params[:edit_id])
if @request.update_attributes(request_params)
flash[:success] = true
redirect_to edit_request_path(@request.edit_id)
else
render 'edit'
end
end
Run Code Online (Sandbox Code Playgroud)
并在"if"中添加一个额外的组件,如下所示:
def update
@request = Request.find_by_edit_id(params[:edit_id])
if @request.update_attributes(request_params) && @request.changed?
flash[:success] = true
redirect_to edit_request_path(@request.edit_id)
else
render 'edit'
end
end
Run Code Online (Sandbox Code Playgroud)
但这不起作用.现在发生的是,在编辑页面上,如果我没有更改任何信息并点击提交,没有任何事情发生(这很好),但如果我改变信息并点击提交,仍然没有任何反应(这是不好的).我究竟做错了什么?
注意:我最初认为这是一个操作错误的顺序,所以我把它作为嵌套if,首先是if @ request.update_attributes,第二个if @ request.changed,但是这个也没有用...
这个问题让我发疯了...我想我已经尝试了Sass文件,ERB文件,资产帮助器,图像助手等各种可能的组合等.有人请给我新的想法!
语境:
Rails应用程序需要使用资产助手,以便在预编译资产时,源将是指纹资产文件.即,如果你刚刚调用了img src ="X.jpg",那么生产中的网站会寻找X.jpg,但是公共/资产中的文件实际上已被指纹化为X-as; diofua; wemfiwaejfoiawefo.jpg.获取指纹文件的唯一方法是使用资产助手,例如image_url('X.jpg').
现在在我的实时网站上,我正在使用资产助手,但无论出于何种原因,它都没有指向指纹资产.请注意,资产是在开发中找到的(但同样,这是因为开发中没有添加指纹).
码
以"classic-map.png"为标题的图片,位于app/assets/images/galleria
从application.css文件中所需的css.erb文件调用映像.在css.erb文件中,我有以下代码:
background-image: url(<%= asset_path 'galleria/classic-map.png' %>);
Run Code Online (Sandbox Code Playgroud)
供参考,http ://guides.rubyonrails.org/asset_pipeline.html请注意,我选择将其写为css.erb文件,因此使用asset_path与asset-path.此外,我最初认为问题可能是插值,但在页面源中,网址肯定是有效的,只是它指向url(galleria/classic-map.png)而不是url(galleria/classic-地图apsoidufalskjf; kasj.png)
对任何可以提供帮助的人都有一百万的荣誉!
好的,所以我觉得我得到了超级does独立的东西.基本上在Devise中,if Users::RegistrationsController < Devise::RegistrationsController,然后在任何动作上,有一个super遗嘱首先在父亲中Devise::RegistrationsController调用同一个命名动作的逻辑,然后再调用你所写的内容.
换一种说法...
class Devise::RegistrationsController
def new
puts "this is in the parent controller"
end
end
class Users::RegistrationsController < Devise::RegistrationsController
def new
super
puts "this is in the child controller"
end
end
# Output if users#new is run would be:
# => "this is in the parent controller"
# => "this is in the child controller"
# If super were reversed, and the code looked like this
# class Users::RegistrationsController < …Run Code Online (Sandbox Code Playgroud) 我需要实现一些后台处理来1)发送电子邮件,2)做一些API调用.而且,无论我使用什么系统,我还将与某种cron调度程序(只要有可能)结合使用.我很好奇,我认识到有一系列非常酷的背景处理宝石(延迟工作,Sidekiq,Resque),但我也明白你可以根据Ryan Bate的视频只用rake任务进行后台处理:http:// railcasts.com/episodes/127-rake-in-background.
使用gem和rake任务进行后台处理的利弊是什么?后者关于我的一件事是,每次调用rake任务时你都必须启动一个新的环境,这在内存上非常昂贵.
请注意,我不需要比较宝石.这个系列在这里做得很好:http: //www.sitepoint.com/series/comparing-ruby-background-processing-libraries/
语境:
最好的例子是 AirBnB。假设我有 5 套公寓。每间公寓都有一个日历,代表它的可用性。当度假者前往我的城市并使用给定的开始日期和结束日期搜索公寓时,如果该时间段在我的任何公寓的日历上显示为可用,我希望这些公寓显示在搜索结果中游客。
一点一点:
显然上面有很多。这个问题的范围是我应该如何为包含可用性的公寓列表设置数据库。在构建数据库之前,我花了一些时间在 Excel 中手动协调,以便在脑海中更清晰地了解一切应该是什么样子。在 Excel 中,我发现可以用作表格的列标题的是:
现在的日历是我遇到的问题。从字面上看,在我的 Excel 中,列只是持续到永恒的日期。每当度假者提交请求时,我都会找到每个日期单元格为空(例如,可用)的所有公寓。然后我将这些公寓送给度假者。当他/她进行预订时,我会返回 Excel 并在所选的特定公寓的每个日期单元格中标记不可用。
我想获得更多意见......这是我应该在 PostGreSQL 中想象我的数据库的正确方式吗?如果是这样......我可以进行如下所示的迁移吗?
class CreateApartments < ActiveRecord::Migration
def change
create_table :apartments do |t|
t.string :apt_name
t.integer :apt_owner
t.text :apt_description
Date.today..Date.new(2034, 12, 31)).each do |date|
t.date :date
end
t.timestamps
end
end
end
Run Code Online (Sandbox Code Playgroud) 错误: h1.js:25 Warning: a promise was rejected with a non-error: [object String]
不完全确定为什么,爱会帮助理解错误以及导致它的原因.仍然学习Promises和AJAX非常感谢!(例如,当我写这篇文章时,我也认为让Promise包装一个ajax对象有点多余,但老实说我不知道如何重新编写它)
var logisticsModule = (function() {
return {
initialize: function() {
dateTimeFxns.getReservedDates.then(
// success
function(reserved_dates) {
console.log("success with value = " + reserved_dates)
},
function(error) {
console.log("error with value = " + error)
}
)
}
}
})();
var dateTimeFxns = {
getReservedDates: new Promise( function(resolve, reject) {
$.ajax({
// some url & data
})
.done(function(result) {
resolve(result)
}
.fail(function(error) {
reject(error)
}
})
}
$(document).ready(function() {
logisticsModule.initialize(); …Run Code Online (Sandbox Code Playgroud) 我在试图让客户端登录工作时遇到了很多问题,所以我将冒昧地引用其他大量问题......没有一个问题导致我的答案对我有用.
CONTEXT
*工作正常,我的意思是如果你只是复制了Ryan Bates的RailsCast(http://railscasts.com/episodes/360-facebook-authentication?view=asciicast)中的代码,它可以在没有任何其他任何东西的情况下工作
TL:DR; 我传递了以下应该有效的网址...
`http://localhost:3000/auth/facebook/callback?signed_request=ASDF.JOUYOUY`
// Obviously signed_request is a much longer string
Run Code Online (Sandbox Code Playgroud)
...但我仍然得到错误 OmniAuth::Strategies::Facebook::NoAuthorizationCodeError (must pass either a代码parameter or a signed request (viasigned_request parameter or afbsr_XXXcookie)):
故障排除日期+许多其他错误/潜在解决方案的概述
下面的代码解决方案基于Ryan Bates的RailsCast的代码:
$('#sign_in').click (e) ->
e.preventDefault()
FB.login (response) ->
window.location = '/auth/facebook/callback' if response.authResponse
Run Code Online (Sandbox Code Playgroud)
障碍#1:第三方cookie被阻止了吗?
不会导致错误,只是使它无法将应用程序连接到Facebook.
首先将您的应用程序连接到Facebook需要您使用Facebook登录,因为代码FB.login (response) -> window.location = "/auth/facebook/callback" if response.authResponse取决于其有效性authResponse及其包含的signedRequest …
javascript facebook omniauth facebook-javascript-sdk omniauth-facebook
我只是想了解我在 Ruby 代码中看到的两种模式。
在 Michael Hartl 的标准教程中,代码如下:
def create
@user = User.new(params[:user])
if @user.save
sign_in @user
flash[:success] = "Welcome to the Sample App!"
redirect_to @user
else
render 'new'
end
end
Run Code Online (Sandbox Code Playgroud)
这是我非常习惯的模式。我刚刚实现了设计,但是它的模式是这样的:
def create
build_resource(sign_up_params)
resource.save
yield resource if block_given?
if resource.persisted?
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_flashing_format?
sign_up(resource_name, resource)
respond_with resource, location: after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?
expire_data_after_sign_in!
respond_with resource, location: after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
set_minimum_password_length
respond_with resource
end
end
Run Code Online (Sandbox Code Playgroud)
为什么resource.persisted?在 if 语句中进行设计检查而不是resource.save …
javascript ×2
ruby ×2
activerecord ×1
ajax ×1
css ×1
database ×1
deferred ×1
delayed-job ×1
devise ×1
facebook ×1
heroku ×1
html ×1
jquery ×1
nested-forms ×1
omniauth ×1
postgresql ×1
promise ×1
puma ×1
rake ×1
resque ×1
sidekiq ×1
sql ×1
super ×1
webrick ×1