I am trying to save form data by form_for new.erb.html
<%= form_for @project do |f| %>
<h4>
<label for = "projectName">Title(required)</label>
<%= f.text_field :projectName, :maxlength => 50 %>
</h4>
<%= f.submit %>
<% end -%>
ProjectsController
class Com::A::B::C::ProjectsController < ApplicationController
def index
@projects = Project.all
end
def new
@project = Project.new
@allTags = Tag.all
@allBenefits = Benefit.all
end
def create
@project = Project.new(project_params)
if @project.save
redirect_to :action => 'index'
else
render :action => 'new'
end
end
def project_params
params.require(:project).permit(:projectName)
end
But nothings getting saved on the database
html tags for text_fiels looks like,
<input id="com_a_b_c_project_projectName" type="text" name="com_a_b_c_project[projectName]" size="50" maxlength="50">
I tried adding url=>"com_a_b_c_project_path" still nothing persists
I am new to rails in ruby, so any help would be nice.
Routes
namespace :com do
namespace :a do
namespace :b do
namespace :c do
get 'projects/index'
resources :projects do
end
end
end
end
end
I get following exception:
param is missing or the value is empty: project
Request
Parameters:
"utf8"=>"✓",
"authenticity_token"=>"",
"com_a_b_c_project"=>{"projectName"=>"s"
"commit"=>"Create Project"
rake rotes
com_a_b_c_projects_index GET /com/a/b/c/projects/index(.:format) com/a/b/c/projects#index com_a_b_c_projects GET /com/a/b/c/projects(.:format) com/a/b/c/projects#index POST /com/a/b/c/projects(.:format) com/a/b/c/projects#create new_com_a_b_c_project GET /com/a/b/c/projects/new(.:format) com/a/b/c/projects#new edit_com_a_b_c_project GET /com/a/b/c/projects/:id/edit(.:format) com/a/b/c/projects#edit com_a_b_c_project GET /com/a/b/c/projects/:id(.:format) com/a/b/c/projects#show PATCH /com/a/b/c/projects/:id(.:format) com/a/b/c/projects#update PUT /com/a/b/c/projects/:id(.:format) com/a/b/c/projects#update DELETE /com/a/b/c/projects/:id(.:format) com/a/b/c/projects#destroy
NOTE I can save data with form_tag But not with form_for... However I need to use form_for otherwise I have to bind object to each field
<%= form_tag :action => 'create', :controller => 'projects' do %>
<h4><label for = "projectName">Title(required)</label> <%= text_field 'project', 'projectName'> </h4>
Cheers
Com::A::B::C::in your controller.project_params' app/controllers/com/a/b/cp/projects_controller.rb:20:increate' Request Parameters: {"utf8"=>"✓", "authenticity_token"=>"", "com_a_b_c_project"=>{"projectName"=>"s" "commit"=>"Create Project"}