在构建基本表单以创建新数据时,我收到以下错误.当我点击提交时,我得到了
simple_form_for NilClass的未定义方法`model_name':Class
**_form.html.erb**
<%= simple_form_for(@calls) do |f| %>
<%= f.error_notification %>
<%= f.input :caller_name %>
<%= f.input :caller_phone, hint: "xxx-xxx-xxxx" %>
<%= f.input :caller_address %>
<%= f.input :primary_diagnosis %>
<%= f.error :base %>
<%= f.button :submit %>
<% end %>
**calls_controller.rb**
def create
@call = Call.new(params[:call])
respond_to do |format|
if @call.save
format.html { redirect_to @call, notice: 'Call was successfully created.' }
format.json { render json: @call, status: :created, location: @call }
else
format.html { render action: "new" }
format.json …Run Code Online (Sandbox Code Playgroud) 我正在编写一个范围,该范围应该查找状态为open且任何日期时间大于当前时间的调用.我对语法有点模糊,有人可以帮助我指出正确的方向.
失败的示例:
scope :scheduled_calls, where(:call_status => "open", :transfer_date > Time.now)
Run Code Online (Sandbox Code Playgroud) 我有一个 Rails 3.2.18 应用程序,我想在其中强制/验证特定格式的电话号码:222-222-2222
我对正则表达式真的很糟糕,并且很难找出与 222-222-2222 匹配的正则表达式模式
我在 Stack 上尝试了一些答案,但它们不是我想要的。
任何帮助是极大的赞赏。
我有一个Rails应用程序,我记录text_field的string是一个电话号码,我想在下面的屏蔽自动格式化xxx-xxx-xxxx
我正在搜索Stack Overflow,发现此自动格式化电话号码在jquery中,但是OP想要格式化的掩码,xxx-xxx-xxx因此我需要弄清楚如何对进行掩码。xxx-xxx-xxxx
我从这个答案中借了一个片段,它确实起作用,但是再次格式化为 xxx-xxx-xxxx
$(function(){
$('#call_caller_phone').keyup(function()
{
this.value = this.value.replace(/(\d{3})\-?/g,'$1-');
});
});
Run Code Online (Sandbox Code Playgroud)
有人可以协助我进行xxx-xxx-xxxx口罩格式化吗?
I have a Rails app where I have a partial that I want a dropdown in so when a user is selected it will do a get method to the urls /timecards/:user_id which will be the controller's show method passing in the User's id field. 我在我的道路上遇到了困难form_tag,可以使用一些帮助。
这是我的部分观点:
<%= form_tag timecard_path, :method => :get do %>
<%= select_tag options_from_collection_for_select(User.employee.order("username ASC"), :id, :username) %>
<%= submit_tag "View Employee", class: "btn btn-primary" %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
从耙路线我得到以下输出:
timecards GET /timecards(.:format) timecards#index …Run Code Online (Sandbox Code Playgroud) 我正在写一个简单的待办事项应用程序,项目和项目有很多任务.我希望能够删除项目中的任务.但是当我尝试link_to一个删除方法时,我得到了未定义的方法'task_path'.
查看代码
<ul>
<% @project.tasks.each do |task| %>
<li><%= task.name %></li> <%= link_to "delete", task, :method => :delete %></br>
<% end %>
</ul>
Run Code Online (Sandbox Code Playgroud)
任务控制器
def destroy
@project = Project.find(params[:project_id])
@task = @project.tasks.find(params[:id])
@task.destroy
redirect_to @project, :notice => "Task Deleted"
end
Run Code Online (Sandbox Code Playgroud)
的routes.rb
resources :projects do
resources :tasks
end
Run Code Online (Sandbox Code Playgroud)
更新:所以我删除了工作.但是现在我正在迭代每个任务,有一个额外的删除链接,它路由到http://todoapp.dev/projects/9/tasks并给出无路由匹配[DELETE]"/ projects/9/tasks"为什么是那里有额外的删除链接?
<% @project.tasks.each do |task| %>
<%= task.name %> <%= link_to "delete", [@project, task], :method => :delete %>
<% end %>
Run Code Online (Sandbox Code Playgroud)


我正在研究Rails/Ruby应用程序中的地理编码片段/ sidekiq作业.所以基本上当我们点击谷歌API时,我们会睡1秒钟以避免谷歌API查询限制.但是我想要考虑AR和SQL时间来推动信封并加快处理速度.所以我想弄清楚如何睡3/4秒.
我可以睡觉.75还是我需要做一些像睡眠一样的睡眠数学(1.0/??).
不确定睡眠是否可以像.75一样浮动.有什么想法吗?
我正在尝试将带有Ruby 2.2.3和Capistrano 3的Rails 4.2.4应用程序部署到VPS服务器.我之前已经多次使用RVM完成了这项工作并且对我的其他应用程序没有任何问题,但是现在我在新机器和服务器上使用rbenv,我得到一个堆栈跟踪,如下所示:
DEBUG [a326a4c8] Command: cd /home/deploy/myapp/releases/20151226231303 && /usr/bin/env bundle install --path /home/deploy/myapp/shared/bundle --without development test --deployment --quiet
DEBUG [a326a4c8] /usr/bin/env:
DEBUG [a326a4c8] bundle: No such file or directory
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy@youspoof.us: bundle exit status: 127
bundle stdout: Nothing written
bundle stderr: /usr/bin/env: bundle: No such file or directory
SSHKit::Command::Failed: bundle exit status: 127
bundle stdout: Nothing written
bundle stderr: /usr/bin/env: bundle: No such file or directory
Tasks: TOP => deploy:updated => bundler:install …Run Code Online (Sandbox Code Playgroud) 我正在开发一个小型 Rails 5.0.0.1 应用程序,它在类似于模因的图像上生成文本。我有在模型中编写的基本代码。
class Meme < ApplicationRecord
require 'mini_magick'
mount_uploader :attachment, AttachmentUploader
def process_image(img_id, top_text, bottom_text)
image = MiniMagick::Image.open(Img.find(img_id).attachment.current_path)
image.combine_options do |c|
c.gravity 'Center'
c.pointsize '22'
c.draw "text 200,200 #{top_text}"
c.fill 'white'
c.draw "text 100,100 #{bottom_text}"
c.fill 'white'
end
self.attachment = image
self.save
end
end
Run Code Online (Sandbox Code Playgroud)
当我从控制台运行它并执行以下操作时:
m = Meme.new
m.process_image(Img.last.id, "Good", "Stuff")
Run Code Online (Sandbox Code Playgroud)
它生成带有正确覆盖的文本的图像。
现在,当我做同样的事情并在这样的标题中包含空格时:
m = Meme.new
m.process_image(Img.last.id, "This is", "Totally Weird")
Run Code Online (Sandbox Code Playgroud)
我在控制台中收到一个异常,如下所示:
mogrify: non-conforming drawing primitive definition `is' @ error/draw.c/DrawImage/3259.
mogrify: non-conforming drawing primitive definition `Weird' @ error/draw.c/DrawImage/3259. …Run Code Online (Sandbox Code Playgroud) ruby ×2
activerecord ×1
bundler ×1
capistrano3 ×1
datetime ×1
forms ×1
imagemagick ×1
javascript ×1
jquery ×1
minimagick ×1
regex ×1
routes ×1
scope ×1
sidekiq ×1
simple-form ×1
validation ×1