我正在尝试从表单创建记录.我使用railscast 136作为地面工作.当我尝试提交时,我因缺少部分而得到500错误.我已经创建了控制器相关的javascript视图,但它正在请求一个与模型同名的视图.
错误信息
渲染约会/ create.js.erb(3.8ms)在12ms内完成500内部服务器错误
ActionView :: Template :: Error(缺少部分约会/约会{:locale => [:en],:formats => [:js,:html],:handlers => [:erb,:builder,:coffee]搜索:*"/ Users/gjores/Sites/Rails/verkstad_test/app/views"):1:$('#appointmentments').append('<%= j render(@appointment)%>') ; app/views/appointmentments/create.js.erb:1:in
_app_views_appointments_create_js_erb___2325925946390315228_70273089113920' app/controllers/appointments_controller.rb:16:increate'
调节器
def create
@appointment = Appointment.new(params[:appointment])
if @appointment.save
respond_to do |format|
format.html { redirect_to new_appointment_path, :notice => "Successfully created appointment." }
format.js
end
else
render :action => 'new'
end
end
Run Code Online (Sandbox Code Playgroud)
约会/ new.html.erb
<div id="appointments">
<%= render 'shared/appointment_part' %>
</div>
<% title "New Appointment" %>
<table>
<% @students.each do |s| %>
<%= form_for @appointment, :remote => true …Run Code Online (Sandbox Code Playgroud) 我正在关注这个 Railscasts插曲.
如果我搜索"Kerber",它确实会返回正确的文章.但是,如果我搜索"Ke",它不会返回相同的文章.
有办法解决这个问题吗?
class Item < ActiveRecord::Base
include PgSearch
pg_search_scope :search, against: [:description, :about, :link, :twitterhandle, :builtby],
using: {tsearch: {dictionary: "english"}}
def self.text_search(query)
if query.present?
search(query)
else
scoped
end
end
Run Code Online (Sandbox Code Playgroud) 我正在关注RailsCast#196 Nested Model Form Part 1.我给出了控制器和模型的相同名称,它是所有属性.但现在当我尝试进行编辑并删除问题时.如果我选中该复选框,则不会删除该问题.
像这样:
模型:
class Survey < ActiveRecord::Base
has_many :questions, :dependent => :destroy
accepts_nested_attributes_for :questions, :reject_if => lambda {|a| a[:content].blank?} , :allow_destroy => true
end
class Question < ActiveRecord::Base
belongs_to :survey
end
Run Code Online (Sandbox Code Playgroud)
调查控制员:
class SurveysController < ApplicationController
before_action :set_survey, only: [:show, :edit, :update, :destroy]
def index
@surveys = Survey.all
end
def show
end
def new
@survey = Survey.new
3.times {@survey.questions.build}
end
def edit
end
def create
@survey = Survey.new(survey_params)
respond_to do |format|
if @survey.save …Run Code Online (Sandbox Code Playgroud) 我刚刚切换到Devise/Omniauth组合,一切都在我的localhost服务器上正常工作.但是,当我上传到heroku时,当用户点击传统注册表单上的注册(而不是omniauth登录)时,应用程序崩溃.我正在使用rails 3.我的日志说
LoadError(没有这样的文件加载--bcrypt):app/controllers/registrations_controller.rb:11在'build_resource'app/controllers/registrations_controller.rb:4 in create'
引用的控制器:
class RegistrationsController < Devise::RegistrationsController
def create
super
session[:omniauth] = nil unless @user.new_record?
end
private
def build_resource(*args)
super
if session[:omniauth]
@user.apply_omniauth(session[:omniauth])
@user.valid?
end
end
end
Run Code Online (Sandbox Code Playgroud)
由于注册控制器超越了Devise,因此第4行和第11行是超级的.出了什么问题?谢谢.
我一直在关注Railscast#270发现Rails Cast#270关于在Rails 3.1中实现身份验证.我想要做的是让我的模板能够在用户登录时显示不同的链接.它应该看起来像这样.
If user logged in
Display link to Profile
Display logout
If user logged out
Display link to register
Display link to login
Run Code Online (Sandbox Code Playgroud)
我想我可以从theRailsTutorial中找出各个地方的链接,但我仍然坚持如何判断用户是否已登录.
使用rails教程我找到了这个片段
<% if signed_in? %>
<li><%= link_to "Profile", current_user %> sfsdfsdf</li>
<% end %>
Run Code Online (Sandbox Code Playgroud)
当我在会话助手中添加以下内容时,哪个不起作用:
def signed_in?
!@current_user.nil?
end
Run Code Online (Sandbox Code Playgroud)
你会怎么做这个工作?
ruby authentication ruby-on-rails railscasts ruby-on-rails-3
我正在使用Carrierwave将图像字段添加到基于Ryan Bates修订的#196截屏视频的Rails嵌套模型中.Carrierwave位基于他的截屏视频#253
问答模型嵌套在类别模型中.
我可以将图像上传并显示在"显示"页面上.但是当我返回编辑视图时,没有图像,我仍然看到"选择文件"按钮旁边的"未选择文件"文本.我可以前往Show页面来回播放它仍然出现在Show中,但从不出现在Edit中.我的用户会认为他们每次都要上传新图片!
我的Show视图中有这行代码:
<%= image_tag question.image_url(:thumb).to_s if question.image? %>
Run Code Online (Sandbox Code Playgroud)
但如果我尝试将其放入_form视图,那么我会得到一个未知的局部变量或方法错误.
我已经尝试了几个if语句,但还没有让它工作.我试图把它全部放在编辑视图中,但无济于事.
我的_form视图:
<%= form_for @category, :html => {:multipart => true} do |f| %>
<% if @category.errors.any? %>
<div class="error_messages">
<h2><%= pluralize(@category.errors.count, "error") %> prohibited this category from being saved:</h2>
<ul>
<% @category.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div id="categorytitle" class="field">
<%= f.label :name, "Category Name" %><br />
<%= f.text_field :name %>
</div>
<%= f.fields_for :questions do |builder| %>
<%= …Run Code Online (Sandbox Code Playgroud) 您好我尝试为我的rails应用创建重置密码; 但是当我尝试保存时,我收到以下错误:
验证失败:密码不能为空,密码太短(最少6个字符),密码确认不能为空
这是我的用户模型.
class User < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation
has_secure_password
before_save { |user| user.email = email.downcase }
before_save :create_remember_token
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false }
validates :password, presence: true, length: { minimum: 6 }
validates :password_confirmation, presence: true
def send_password_reset
self.password_reset_token = SecureRandom.urlsafe_base64
self.password_reset_at = Time.zone.now
self.password = self.password
self.password_confirmation = self.password
save!
end
private
def create_remember_token
self.remember_token = SecureRandom.urlsafe_base64
end
end
Run Code Online (Sandbox Code Playgroud)
方法"send_password_reset"不会更新用户,我不明白为什么尝试保存用户而不是只更新password_reset_token和password_reset_at.
请问有人可以帮助我吗?
这段代码来自Ryan Bates的Railscast第343集,内容是关于PostgreSQL中的全文搜索.我想理解它,但我在<<-操作员身上找不到任何东西(如果它甚至是操作员).有人可以指点我到某个地方,我可以了解这个吗?
rank = <<-RANK
ts_rank(to_tsvector(name), plainto_tsquery(#{sanitize(query)})) +
ts_rank(to_tsvector(content), plainto_tsquery(#{sanitize(query)}))
RANK
Run Code Online (Sandbox Code Playgroud) 服务器声明电子邮件已发送到正确的地址,但我没有收到收件箱中的邮件.
我的Setup_mail.rb文件
ActionMailer::Base.smtp_settings ={
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "my_user_name@gmail.com",
:password => "my_password",
:authentication => "Plain",
:enable_starttls_auto => true
}
Run Code Online (Sandbox Code Playgroud)
我的development.rb档案是:
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true #default value
config.action_mailer.delivery_method = :smtp #default value
Run Code Online (Sandbox Code Playgroud)
我的test.rb档案是:
config.action_mailer.delivery_method = :smtp
Run Code Online (Sandbox Code Playgroud)
我尝试了多种变化而且迷失了.我在Windows 7机器上运行.我正在运行Ruby 1.8.7和Rails 3.0.7
有人可以帮忙吗?
这是我的创建方法:
def create
@user = User.new(params[:user])
if @user.save
UserMailer.registration_confirmation(@user).deliver
sign_in @user
redirect_to @user, :flash => { :success => "Welcome …Run Code Online (Sandbox Code Playgroud) 我正在关注Ryan Bates的RailsCast#288"Billing with Stripe",当我修改我的表单以包含信用卡信息时,我收到以下错误:
compile error
/Programs/domainster/app/views/domains/_form.html.erb:23: syntax error, unexpected ':', expecting ')'
...d_tag :card_number, nil, name: nil );@output_buffer.safe_con...
Run Code Online (Sandbox Code Playgroud)
我检查了RailsCast的语法,代码完全相同.我甚至更新了我的GemFile以确保我有最新的Rails运行.
这是我的表格:
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :description %><br />
<%= f.text_area :description %>
</div>
<div class="field">
<%= label_tag :card_number, "Credit Card Number" %><br />
<%= text_field_tag :card_number, nil, name: nil %>
</div>
<div class="field">
<%= label_tag :cvv, "Security Code on Card (CVV)" %><br />
<%= text_field_tag :cvv, nil, name: …Run Code Online (Sandbox Code Playgroud) 这个令牌输入来自 http://loopj.com/jquery-tokeninput/
我看到http://railscasts.com/episodes/258-token-fields-revised的教程
因为我在很多地方使用它,我需要一些时间只选择一个值,而在其他地方需要多个值.它是多值选择的代码.现在我希望它只搜索一次并只提交一个值.有没有办法在我的coffescript文件中编码它只选择一个值并停止?
my code for customers.js.coffee
jQuery ->
$('#customer_plan_tokens').tokenInput '/plans.json'
theme: 'facebook'
prePopulate: $('#customer_plan_tokens').data('load')
my code for _form.html.erb for cusomers is
<div class="form-inputs-right">
Projects: <%= f.text_field :plan_tokens, data: {load: @customer.plans}, :label => "Projects" %>
</div>
Run Code Online (Sandbox Code Playgroud) 我正在关注RyanB的多态关联视频,该视频显示了实施评论系统的示例.
http://railscasts.com/episodes/154-polymorphic-association-revised?autoplay=true
我想知道如何将用户名添加到创建新评论的人的数据库中?这样我可以在视图页面中显示用户名,
谢谢
railscasts ×13
ruby-on-rails ×12
ruby ×6
jquery ×2
nested-forms ×2
actionmailer ×1
ajax ×1
carrierwave ×1
coffeescript ×1
devise ×1
heroku ×1
pg-search ×1
postgresql ×1
super ×1
syntax-error ×1