Rails form not creating object

Posted by user2136807 on Stack Overflow See other posts from Stack Overflow or by user2136807
Published on 2013-07-01T04:18:30Z Indexed on 2013/07/01 4:20 UTC
Read the original article Hit count: 95

Filed under:
|

I have created a simple form to create an instance of a modle and for some reason it is not calling the create method in the controller. Here is the form code:

<% @house.mates.each do |mate| %>
    <p><%= mate.name %></p>
<% end %>

<h2>Add a new mate:</h2>
<%= form_for @mate do |f| %> 
    <p><%= f.label "Name" %>
       <%= f.text_field :name %>
       <%= f.hidden_field :house_id %>
   </p>
   <%= f.submit "Submit", :action => :create %>
<% end %>

Here is the controller code:

class MatesController < ApplicationController

  def new 
    @mate = Mate.new
  end

  def create 
    @mate = Mate.new(params[:mate])
    @mate.save
    redirect_to house_path(current_house)
  end

end

There is a many to one relationship between the Mate model and the House model... I am fairly new to rails but I have made other apps with similar forms, and I have never had this problem before. I can create and save Mate objects in the console, and I am not getting any errors, so it seem that somehow the controller method is not being called. Any help is much appreciated!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about forms