Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Undefined Method Input

Hi Guys - Happy New Year!

I am following the social networking track for Ruby and running into the following error:

undefined method `input' for #<ActionView::Helpers::FormBuilder:0x007ff4eeb498b8>

       </div>
     <% end %>

     <%= f.input :user_id, collection: User.all, label_method: :full_name %>
     <%= f.input :content %>
     <div class="form-actions">
       <%= f.button :submit %>

My _form partial looks like this:

<%= form_for(@status) do |f| %>
  <% if @status.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@status.errors.count, "error") %> prohibited this status from being saved:</h2>

      <ul>
      <% @status.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <%= f.input :user_id, collection: User.all, label_method: :full_name %>
  <%= f.input :content %>
  <div class="form-actions">
    <%= f.button :submit %>
  </div>
<% end %>

My project is here: https://github.com/allcentury/treebook

I'm a bit unsure as to why these text fields aren't working, did something change in Ruby 2/Rails 4?

Naomi Freeman
Naomi Freeman
Treehouse Guest Teacher

I also ran into this, and fixed it! It was this summer. Let me review my code on Github, go back through my notebooks, eat some food and reply? Talk soon. I know it can be frustrating to wait. Just not clear-headed enough to compare atm. I promise to get back to you though.

3 Answers

Naomi Freeman
STAFF
Naomi Freeman
Treehouse Guest Teacher

First, the full_name was not defined in the model yet. I've sent you a pull request on your github which should be able to be merged no problem. Just click the green buttons and follow the instructions on github.

The second thing that I ran into when I did this, which I haven't updated in yours, is in the controller, I believe the statuses controller, where there is params.require(:status).permit(:content, :user_id) you have to change :user_id to :full_name. Sorry - in yours that is set to (:name, :content) rather than (:content, :user_id). Either way, you have to change it to full_name or add full_name so that it's allowed when you're posting a status. I can't remember if there are other places in the controllers where this permission stuff happens too.

Any place in your controllers where you have some kind of .permit will have to have this addition or change or the program will not allow full_name since you have programmed it to only allow things that are not full_name. Does that make sense?

I just wanted to do the model piece first (which I submitted as a pull request) and then once full_name does exist in your program, go and change the .permit

Hope that works :)

Hi Naomi - Thanks! I think the issue is somewhere in the devise controller though, as the methods calling on it seem to return nil. I opened up a separate discussion because I am stuck and unsure what's out of date! https://teamtreehouse.com/forum/devise-validation-issues

Hi Anthony. I suppose that you missed one little thing here:

<%= form_for(@status) do |f| %>

Try to add "simple_" to make it look like this:

<%= simple_form_for(@status) do |f| %>