class TicketsController < ApplicationController
before_action :set_project
before_action :set_ticket, only: [:show, :edit, :update, :destroy]
def show
end
def set_ticket
@ticket = @project.tickets.find(params[:id])
end
def set_project
@project = Project.for(current_user).find(params[:project_id])
rescue ActiveRecord::RecordNotFound
flash[:alert] = "The project you were looking " +"for could not be found."
redirect_to root_path
end
end
Run Code Online (Sandbox Code Playgroud)
项目的模板- show.html.erb
<% @project.tickets.each do |ticket| %>
<li>
#<%= ticket.id %> - <%= link_to ticket.title, [@project, ticket] %>
</li>
<% end %>
Run Code Online (Sandbox Code Playgroud)
我收到错误:uninitialized constant Project::Ticket显示模板的第一行
这是在我的路由文件中
resources :projects do
resources :tickets
end …Run Code Online (Sandbox Code Playgroud) 我正在使用 Ruby 2.3.0 和 Rails 4.2.6。我在参数中有一个带有嵌套哈希数组的哈希,当我将其写入文件时
hash = {"abc"=> [{"abc1"=>[{"key1" => value1},{"key2" => value2}]}]}
File.open("abc.yaml",'w+') {|f| f.write hash.to_yaml(:indentation => 8) }
Run Code Online (Sandbox Code Playgroud)
abc.yaml
---
abc:
- !ruby/hash-with-ivars:ActionController::Parameters
elements:
abc1: &2
- !ruby/hash-with-ivars:ActionController::Parameters
elements:
key1: value1
key2: value2
ivars:
:@permitted: false
- !ruby/hash-with-ivars:ActionController::Parameters
elements:
key1: value1
key2: value2
ivars:
:@permitted: false
ivars:
:@permitted: false
:@converted_arrays: !ruby/object:Set
hash:
*2: true
Run Code Online (Sandbox Code Playgroud)
这里提到它 是因为在 psych gem 的 2.0.9 版本中添加了序列化 hash-with-ivars 的功能。psych gem 现在是 Ruby 标准库的一部分,并且它的这个特定版本已添加到 stdlib 2.3.0 Preview1 版本中。
但我试图通过不添加任何其他额外参数来保持 yaml 文件干净。如何在写入文件时删除 !ruby/hash-with-ivars: ActionController::Parameters …
我在 Windows 8 中安装了 Rails 4.1.8,其 ruby 版本为“ruby 2.1.5p273(2014-11-13 修订版 48405)[i386-mingw32]”。我按照本教程在 Rails 上安装 ruby-” http://installfest。 railsbridge.org/installfest/windows “。现在,每当我运行任何 Rails 应用程序时,我都会收到此错误 -
Fetching source index from https://rubygems.org/
Retrying source fetch due to error (2/3):Bundler::Fetcher::CertificateFailureError
Could not verify the SSL certificate for https://rubygems.org/.
There is a chance you are experiencing a man-in-the-middle attack, but most likely your system doesn't have the CA certificates needed for verification. For information about OpenSSL certificates, see bit.ly/ruby-ssl. To connect without using SSL, edit your Gemfile sources and …Run Code Online (Sandbox Code Playgroud) 我在导轨中使用FCM宝石
fcm = FCM.new(Rails.application.config.api_key)
registration_ids= ["<got from android app>"] # an array of one or more client registration tokens
options = {data: {score: "123"}, collapse_key: "updated_score"}
response = fcm.send(registration_ids, options)
puts "response: #{response}"
Run Code Online (Sandbox Code Playgroud)
我收到错误消息:“验证发件人帐户时出错”
响应是:
ma = 2592000; v = \“ 37,36,35 \”“”,“ accept-ranges”:[“ none”],“ vary”:[“ Accept-Encoding”],“ connection”:[“ close”]},“ status_code“:401,” response“:”验证发件人帐户时出错。“}
在搜索时,我发现我需要将服务器列入白名单。我正在使用heroku服务器。在哪里可以将其列入白名单?请帮忙
我正在使用Rails 4并设计3.2.在注册时,通过电子邮件向新注册的用户发送激活/确认链接.我已经在Devise wiki中的这篇文章中实现了这一点.
每当我输入相同的密码时,他们都会毫无问题地登录,但是当我在第一次尝试中输入密码错误并且在第二次尝试时输入相同的密码时,它不起作用.
这是出现的错误
NoMethodError in ConfirmationsController#update
undefined method `add_error_on' for ConfirmationsController:Class
Run Code Online (Sandbox Code Playgroud)
class ConfirmationsController < Devise::ConfirmationsController
skip_before_filter :require_no_authentication
skip_before_filter :authenticate_user!
# PUT /resource/confirmation
def update
with_unconfirmed_confirmable do
if @confirmable.has_no_password?
@confirmable.attempt_set_password(params[:user])
if @confirmable.valid? and @confirmable.password_match?
do_confirm
else
do_show
@confirmable.errors.clear #so that we wont render :new
end
else
self.class.add_error_on(self, :email, :password_already_set)
end
end
if !@confirmable.errors.empty?
render 'devise/confirmations/new'
end
end
# GET /resource/confirmation?confirmation_token=abcdef
def show
with_unconfirmed_confirmable do
if @confirmable.has_no_password?
do_show
else
do_confirm
end
end
if !@confirmable.errors.empty?
self.resource …Run Code Online (Sandbox Code Playgroud)