小编Sus*_*hil的帖子

使用嵌套表单时,无法批量分配受保护的属性设计错误

我搜索了很长时间,但找不到解决方案.这是我的模特:

web.rb

class Web < ActiveRecord::Base
   devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable

  attr_accessible :email, :password, :password_confirmation, :user_type, :remember_me

  belongs_to :role, :polymorphic => true
end
Run Code Online (Sandbox Code Playgroud)

user.rb

class User < ActiveRecord::Base
 has_one :web, :as => :role
 attr_accessible :dob, :fname, :lname
end
Run Code Online (Sandbox Code Playgroud)

org.rb

class Org < ActiveRecord::Base
  has_one :web, :as => :role
  attr_accessible :name, :website
end
Run Code Online (Sandbox Code Playgroud)

一切似乎没问题,直到我在devise/registration/new.html.erb中使用simple_form_for而不是普通的form_for

<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :class => 'form-horizontal' }) do |f| %>

  <%= f.input :email, label: false, :input_html => …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails devise simple-form

7
推荐指数
1
解决办法
512
查看次数

类的解析列值总是为零

在使用查询获取对象时,仅获取某些列,其余列为nil.我也试过fetchIfNeededInBackgroundWithBlock但没有运气.

查询:

let query = PFQuery(className:"Order")
query.whereKey("buyerUser", equalTo: PFUser.currentUser()!)
query.findObjectsInBackgroundWithBlock { (orders: [PFObject]?, error: NSError?) -> Void in
    if(error == nil){
        print(orders?.first)
    }
}
Run Code Online (Sandbox Code Playgroud)

输出:

Optional(<Order: 0x7ff778011940, objectId: KytyBZD9zV, localId: (null)> {
buyerUser = "<PFUser: 0x7ff77353e520, objectId: xxxxx, localId: (null)>";
charged = 1;
fulfilled = 0;
item = "<Item: 0x7ff778011dd0, objectId: GN277W4mO0, localId: (null)>";
shippingUser = "<PFUser: 0x7ff778012270, objectId: xxxx, localId: (null)>";
stripePaymentId = "xxxxxx";})
Run Code Online (Sandbox Code Playgroud)

Order Parse数据浏览器中的类

订单类

如果我尝试transactionId使用以下代码访问:

let order = orders?.first
print(order.objectForKey("transactionId"))
Run Code Online (Sandbox Code Playgroud)

结果总是如此nil. …

ios parse-platform swift

7
推荐指数
1
解决办法
185
查看次数

Rails 在服务器启动时初始化变量

我想在 rails 中初始化一个变量并在控制器的操作中使用它,但是当服务器启动时该变量应该有一个固定值。我尝试在控制器的动作中定义它,并且它为每个请求获得相同的初始化值。例如,我想初始化一个 date.now 并在 15 天后也有相同的日期。

更新 我正在实施一个即将推出的页面,其中显示 15 天后的计时器。如果我在控制器内的操作中实现它,它会在每次调用该操作时显示新日期。

请帮忙

initialization ruby-on-rails ruby-on-rails-3

3
推荐指数
1
解决办法
2648
查看次数

如何在链接中没有.pdf的情况下在ruby中下载pdf文件

我需要使用 ruby​​ 从不提供以 (.pdf) 结尾的链接的网站下载 pdf。手动地,当我单击链接下载 pdf 时,它会将我带到一个新页面,并且一段时间后会出现保存/打开文件的对话框。

请帮我下载该文件。

链接

ruby pdf download

0
推荐指数
1
解决办法
5156
查看次数

用户使用设计登录后重定向到路径时出错

我正在开发rails应用程序上的ruby,我希望用户在使用devise成功登录后重定向到特定页面.我的设计会话控制器中有以下代码:

protected
def after_sign_in_path_for(resource)
 if resource.role == "User"
  redirect_to user_home_path
 else
  redirect_to org_home_path
 end
end
Run Code Online (Sandbox Code Playgroud)

我已将控制器设置为根据重定向显示页面.但是,登录后会显示以下错误:

 AbstractController::DoubleRenderError in Webs::SessionsController#create

Render and/or redirect were called multiple times in this action. Please note that you  may only call render OR redirect, and at most once per action. Also note that      neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return".
Run Code Online (Sandbox Code Playgroud)

我搜索过,但没有运气.请帮忙.

ruby-on-rails devise

0
推荐指数
1
解决办法
783
查看次数