我试着开发一些关于日期的表格的redmine插件。
当我试图配置路由设置时,rails显示了这个错误我修不好。问题在哪里?
我得到这个错误:

/days/new.html.erb:20: syntax error, unexpected tLABEL, expecting keyword_end ...ppend= form_for(@daysoff) url: {action: "create"} do |f| @o... ... ^ /var/www/redmine/plugins/days_off_redmine/app/views/days/new.html.erb:20: syntax error, unexpected keyword_do_block, expecting keyword_end ...off) url: {action: "create"} do |f| @output_buffer.safe_appe... ... ^ /var/www/redmine/plugins/days_off_redmine/app/views/days/new.html.erb:44: syntax error, unexpected keyword_ensure, expecting end-of-input

配置/路由.rb
get 'days_off_redmine', :to => 'days#index'
get 'days_off_redmine/new', :to => 'days#new'
post 'days_off_redmine', :to => 'days#create'

型号/天数
class Daysoff < ActiveRecord::Base
unloadable
end

天控制器.rb
class DaysController < ApplicationController
  unloadable

    def index


  end

  def new
    @people = User.all
    @user = User.current

    @daysoff = Daysoff.new
  end

  def create
  end



end

天/index.html.erb
<%= link_to 'New', days_off_redmine_new_path %>

天/new.html.erb
<%= form_for(@daysoff) url: {action: "create"} do |f| %>
<%= f.date_field :date, id: 'altField' %>
<%= f.select_field "user", options_from_collection_for_select(@people, "id", "name"), prompt: "Select user" %>
<%= f.submit "Submit" %>
<% end %>

额外问题:实际上我不需要额外的页面,如何在索引控制器中发布我的表单?

最佳答案

将表单更改为:

<%= form_for @daysoff do |f| %>
  <%= f.date_field :date, id: 'altField' %>
  <%= f.select_field "user", options_from_collection_for_select(@people, "id", "name"), prompt: "Select user" %>
  <%= f.submit "Submit" %>
<% end %>

实际上我不需要额外的页面,如何在索引控制器中发布我的表单?
只要在索引操作中实例化@daysoff和@people变量,就可以了。
def index
  @people = User.all
  @user = User.current

  @daysoff = Daysoff.new
end

关于ruby-on-rails - 语法错误,意外的keyword_do_block,期望keyword_end…off,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31017274/

10-11 06:25