我在索引(pieces_path)中有这个
<%= form_tag (upload_pieces_path) do%>
<%= file_field_tag 'data' %>
<%= submit_tag %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
而这在片段控制器中
def upload
file_data = params[:data]
File.read(file_data, 'r') do |file|
file.each do |line|
## .... ##
end
end
redirect_to pieces_path
end
Run Code Online (Sandbox Code Playgroud)
最后的路线
match '/upload_pieces', to: 'pieces#upload', via: 'post'
Run Code Online (Sandbox Code Playgroud)
想法是在视图中读取文件,然后对他做一些事情,而不是将其保存在数据库中,然后返回上一页.
但是当我测试它时,我上传文件时收到"没有这样的文件或目录"错误.
有什么想法吗?我做错了什么?
为什么我的服务器不能简单地使用rails s启动
? rails s
/usr/local/var/rbenv/versions/2.1.0/lib/ruby/2.1.0/rubygems/dependency.rb:298:in `to_specs': Could not find 'minitest' (~> 5.1) - did find: [minitest-4.7.5] (Gem::LoadError)
? bundle exec rails s
=> Booting Thin
=> Rails 4.0.3 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Thin web server (v1.6.1 codename Death Proof)
Maximum connections set to 1024
Listening on 0.0.0.0:3000, CTRL+C to stop
Run Code Online (Sandbox Code Playgroud) 我正在使用Rails 4并设计,当我尝试从我的管理控制台更新用户时遇到问题(我正在使用Rails管理员).每次我尝试更新时,都会给我一个错误:
ActiveRecord::RecordNotUnique (PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_users_on_unlock_token"
Run Code Online (Sandbox Code Playgroud)
这可能是因为大多数用户的unlock_token字段为空.但是肯定可以为null的字段仍可以编入索引吗?只有当用户被锁定在他们的帐户之外时才设置unlock_token?
我可以通过在确认令牌字段中输入随机字符串来轻松避免此问题,但这似乎是处理它的一种不好的方法.有更好的想法吗?
我的用户表定义(以及它的相关部分):
create_table "users", force: true do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "screen_name"
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.integer "failed_attempts", default: 0
t.string "unlock_token"
t.datetime "locked_at"
end
Run Code Online (Sandbox Code Playgroud)
我的日志错误:
SQL (10.5ms) UPDATE "users" SET "unlock_token" = $1, "updated_at" = $2 …Run Code Online (Sandbox Code Playgroud) 例如,我见过设计师做的事情:
@font-face {
font-family: 'ProximaNovaRegular';
src: url("<%= font_path('PrimaNova-Regular.otf') %>");
src: url("<%= font_path('PrimaNova-Regular.otf') %>") format("opentype"),
url("<%= font_path('proximanova-regular-webfont.woff') %>") format('woff'),
url("<%= font_path('proximanova-regular-webfont.ttf') %>") format('truetype'),
url("<%= font_path('proximanova-regular-webfont.svg#ProximaNovaRegular') %>") format('svg');
}
Run Code Online (Sandbox Code Playgroud)
有几种不同格式的目的是什么?只需一个就够了吗?我正在使用@ font-face添加字体到我的应用程序,但是我只有.otf格式 - 可以吗?
这是我的config/unicorn/development.rb
app_path = "/home/ec2-user/apps/app_dev/current"
worker_processes 1
preload_app false
timeout 300
listen 3333
working_directory app_path
pid "#{app_path}/tmp/pids/unicorn.pid"
rails_env = 'development'
stderr_path "log/unicorn.log"
stdout_path "log/unicorn.log"
Run Code Online (Sandbox Code Playgroud)
这是我的Capfile
# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
require 'capistrano/bundler'
# require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano3/unicorn'
# require 'sidekiq/capistrano'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
Run Code Online (Sandbox Code Playgroud)
"cap development unicorn:start" …
这是我的link_to标签:
<%= link_to "Signout", dasharea_signout_path, method: "delete", id: "adminsignout" %>
Run Code Online (Sandbox Code Playgroud)
我需要补充一下
<i class="fa fa-tasks">
Run Code Online (Sandbox Code Playgroud)
进入上面代码创建的'a'标签.我怎样才能做到这一点?
这是我用于在表单中呈现下拉列表的代码.
<label class= 'sniglet'> Nationality</label>
<%= f.select(:nationality_id, @nationalities.map {|n| [n.country_name, n.id]}, :class => 'form-control') %>
Run Code Online (Sandbox Code Playgroud)
默认的引导程序样式似乎不起作用.可能是什么问题呢?
我有一个Rails 4应用程序,它使用Mandrill发送电子邮件.我正在尝试检测邮件被打开或弹回的天气,所以我正在使用webhooks.我成功收到了webhooks,但我无法分辨哪些人从我的数据库中识别出特定的电子邮件.
我试过用这个
def send_message(email)
mail( from: ...,
to: ...,
subject: ...)
headers["X-MC-AutoHtml"] = "true"
headers["X-MC-Track"] = "opens"
headers['X-MC-MergeVars'] = { "id" => some_id }.to_json
end
Run Code Online (Sandbox Code Playgroud)
但是我不确定我是否应该收回X-MC-MergeVars(这是我从文档中理解的)
不幸的是,它没有用.
您有任何想法或替代解决方案吗?谢谢
我有一个友好的模型,但是当我在我的用户/节目视图中包含此代码时,我得到了这个不需要的结果:
Friends
Dave Olson, accepted
[#<Friendship id: 74, user_id: 1, friend_id: 2, status: "accepted", created_at: "2014-03-27 03:54:08", updated_at: "2014-03-27 03:54:09">]
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚为什么额外的哈希打印出来.
这是我的观点中的代码:
<h3>Friends</h3>
<%= @user.friendship.each do |friendship| %>
<p><%= friendship.friend.name %>, <%= friendship.status %></p>
<% end %>
Run Code Online (Sandbox Code Playgroud)
用户模型是:
class User < ActiveRecord::Base
rolify
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :invitable, :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :trackable, :validatable
has_many :items
has_many :friendship
end
Run Code Online (Sandbox Code Playgroud)
以及我的友谊模型的相关部分:
class Friendship < ActiveRecord::Base
belongs_to :user
belongs_to :friend, …Run Code Online (Sandbox Code Playgroud) 试图在我的博客文章中添加验证,所以当你尝试添加少于5个字符的标题时,你会收到一条错误消息,但此刻我收到此错误消息 -
NameError in Posts#create
& undefined local variable or method `msg' for #<#<Class:0x007fce95ca04c0>:0x007fce95b4a300>
Run Code Online (Sandbox Code Playgroud)
new.html.erb
<div class = "container">
<h1> New Post </h1>
<%= form_for :post, url: posts_path do |f| %>
<% if @post.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul>
<% @post.errors.full_messages.each do [msg] %>
<li><%= msg %></li> <error
<% end %>
</ul>
</div>
<% end %>
<p>
<%= f.label :title %><br>
<%= f.text_field :title %>
</p>
<%= f.label :text %><br>
<%= …Run Code Online (Sandbox Code Playgroud) ruby-on-rails-4 ×10
css ×2
ruby ×2
amazon-ec2 ×1
capistrano3 ×1
css3 ×1
devise ×1
file-upload ×1
filepath ×1
html5 ×1
mandrill ×1
ruby-2.1 ×1
unicorn ×1