syntax error, unexpected keyword_do_block, expecting keyword_end ...off

2.4k views Asked by At

I'm try to develop redmine plugin which have some forms about dates. When I try to configure route settings, rails showed me this error. I couldn't fix it. Where is the problem?

I got this error:

/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

config/routes.rb

get 'days_off_redmine', :to => 'days#index'
get 'days_off_redmine/new', :to => 'days#new'
post 'days_off_redmine', :to => 'days#create'

model/daysoff.rb

class Daysoff < ActiveRecord::Base
unloadable
end

days_controller.rb

class DaysController < ApplicationController
  unloadable

    def index


  end

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

    @daysoff = Daysoff.new
  end

  def create
  end



end

days/index.html.erb

<%= link_to 'New', days_off_redmine_new_path %>

days/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 %>

Extra Question: Actually I don't need extra page, how can post my form in the index controller?

3

There are 3 answers

0
Mandeep On BEST ANSWER

Change your form to this:

<%= 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 %>

Actually I don't need extra page, how can post my form in the index controller?

Just instantiate @daysoff and @people variables inside index action and you are good to go.

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

  @daysoff = Daysoff.new
end
0
Leo Silence On

you missing , like:

<%= form_for @daysoff, url: {action: "create"} do |f| %>
0
smathy On
<%= form_for(@daysoff) url: {action: "create"} do |f| %>
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            this should be arguments to the form_for method

...but you closed the parentheses and so there's a syntax error, it should be:

<%= form_for(@daysoff, url: {action: "create"}) do |f| %>

...or, more idiomatically, just:

<%= form_for @daysoff, url: {action: "create"} do |f| %>