I have a form where I am trying to do a very simple CRUD operations on rails with MongoDB.
I have my controller
class RecipesController < ApplicationController
def new
@recipe = Recipe.new
end
def update
end
def create
recipe = Recipe.create(params[:title])
redirect_to params[:title]
@recipes = Recipe.all
end
def index
@recipes = Recipe.all
end
end
my form
<%= form_for Recipe.new do |f| -%>
<%= f.text_field :title %>
<%= f.submit "Create Recipe" %>
<% end %>
seems pretty basic to me. However, the params are not getting through to the controller it seems.
I can see the params passed through webrick
Started POST "/recipes" for 127.0.0.1 at 2010-09-02 14:15:56 -0800
Processing by RecipesController#create as HTML
Parameters: {"authenticity_token"=>"8oyq+sQCAEp9Pv864UHDoL3TTU5SdOXQ6hDHU3cIlM
Y=", "recipe"=>{"title"=>"test"}, "commit"=>"Create Recipe"}
Rendered recipes/create.html.erb within layouts/application (4.0ms)
Completed 200 OK in 51ms (Views: 16.0ms)
but the redirect_to params[:title] returns a nil value error.
I noticed that 'title' is inside the 'recipe' parameter, and wasn't sure if that may be part of the issue.
One of the the many things that has me confused is that I never actually have to call create? Is that right? I'm calling 'new' on the form, and for some reason rails automatically calls 'create'?