Generating forms with a self-defined helper

im currently trying to implement a form with several buttons, and my
solution for that was to make a full form for each of the 5 buttons.
thats extremely repetitive, so i wanted to generate the forms with a
helper function that i define myself, but i cant make it work.

my form method:

module ApplicationHelper
def raw_datum_new_helper(status)

form_for(@raw_datum) do |f|
  if @raw_datum.errors.any?
  "<div id='error_explanation'>"
    "<h2>#{pluralize(@raw_datum.errors.count, "error"})prohibited

this raw_datum from being saved:"


    @raw_datum.errors.full_messages.each do |msg|
    "
  • #{msg}

  • #{end}

"
<% end %>
"<div class='field'>"
#{f.hidden_field :timestamp, :value => Time.now.to_s[0,16]
  f.hidden_field :status, :value => status}
</div><div class='actions'>"
  f.submit :value => status
"</div>"
end

end
end

my errors when calling <%= raw_datum_new_helper(“ins Bett gelegt”) %>:
/home/rynnon/workspace-ruby/sleepdata/app/helpers/application_helper.rb:15:
syntax error, unexpected ‘}’, expecting ‘)’
…aw_datum.errors.count, “error”})prohibited this raw_datum fr…
… ^
/home/rynnon/workspace-ruby/sleepdata/app/helpers/application_helper.rb:15:
syntax error, unexpected ‘:’, expecting ‘}’
…his raw_datum from being saved:"
… ^
/home/rynnon/workspace-ruby/sleepdata/app/helpers/application_helper.rb:18:
unknown regexp option - l
/home/rynnon/workspace-ruby/sleepdata/app/helpers/application_helper.rb:20:
syntax error, unexpected ‘<’

^
/home/rynnon/workspace-ruby/sleepdata/app/helpers/application_helper.rb:21:
unknown regexp options - dv
/home/rynnon/workspace-ruby/sleepdata/app/helpers/application_helper.rb:24:
syntax error, unexpected keyword_class, expecting keyword_do or ‘{’ or
‘(’


^
/home/rynnon/workspace-ruby/sleepdata/app/helpers/application_helper.rb:30:
syntax error, unexpected keyword_end, expecting ‘}’

Does anyone have an idea as to how to go about this?

Hi

On Sun, Jun 12, 2016, at 01:51, Rynn S. wrote:

form_for(@raw_datum) do |f|
<% end %>

end

Rails helper is normal ruby method so you can’t write it like erb. There
also a few syntax errors.

You’ll be better off writing partial instead of helper.

nanaya wrote in post #1183937:

Hi

Rails helper is normal ruby method so you can’t write it like erb. There
also a few syntax errors.

You’ll be better off writing partial instead of helper.

Thank you! I just did that (iterated over an array with the variables
that change), it was definitely less hassle than trying to make the
function work.