Michael Lombardo Michael Lombardo - 6 months ago 28
HTML Question

undefined method `input' for "NoMethodError in Revisers#new "

I'm trying to get this form to work.

Revisers
has a
has_one
relationship to
User
.

new.html:


<div class="container">

<%= form_for @reviser, url: new_user_reviser_path(user_id: current_user.id) do |f| %>

<div class="row">
<div class="div.col-md-4 select">
<div class="form-group">
<label>dsd</label>
<%= f.input :description %>
</div>

</div>
</div>
<%= f.submit "Become Adviser", class: "btn btn-large btn-primary" %>
<% end %>
</div>
</div>





Error Log:

Rendered revisers/_form.html.erb (30.8ms)
Rendered revisers/new.html.erb within layouts/application (31.7ms)
Completed 500 Internal Server Error in 38ms (ActiveRecord: 0.3ms)

ActionView::Template::Error (undefined method `input' for #<ActionView::Helpers::FormBuilder:0x007faf35829f10>):
11: <div class="div.col-md-4 select">
12: <div class="form-group">
13: <label>dsd</label>
14: <%= f.input :description %>
15: </div>
16:
17: </div>
app/views/revisers/_form.html.erb:14:in `block in _app_views_revisers__form_html_erb___2471522092853631188_70195247159960'
app/views/revisers/_form.html.erb:8:in `_app_views_revisers__form_html_erb___2471522092853631188_70195247159960'
app/views/revisers/new.html.erb:1:in `_app_views_revisers_new_html_erb___1451348464463745171_70195280947160'


reviserController:

class RevisersController < ApplicationController

before_action :set_reviser, only: [:show, :edit, :update]
before_action :authenticate_user!, except: [:show]

def index
@reviser = current_user.reviser
end

def show

end

def new
@reviser = current_user.build_reviser(params[:reviser])
@user = User.find(params[:user_id])
end

def create
@reviser = current_user.reviser.build(reviser_params)

if @reviser.save
redirect_to @reviser,notice: "saved...."
else
render :new
end
end

def edit
set_reviser
end

def update
set_reviser
if @reviser.update(reviser_params)
redirect_to @reviser,notice: "updated.."
else
render :edit
end
end

private
def set_reviser
@reviser = current_user.reviser
end

def reviser_params
params.require(:reviser).permit(:description, :average_start, :average_end, :max_pages, :price_per, :active)
end
end

Answer

f.input isn't defined for the default Rails form helpers. You may be getting confused with the Formtastic/SimpleForm syntax which does use f.input.

If you're not using Simple Form or Formtastic, then simply use the standard form helper methods provided by Rails here: http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html

<%= f.text_field :description %>