Reputation: 119
I am using Rails version 3.2.19
Error:
TypeError in UsersController#create
can't convert Symbol into String
Rails.root: C:/Site/myapp1
Application Trace | Framework Trace | Full Trace
app/controllers/users_controller.rb:25:in `user_params'
app/controllers/users_controller.rb:12:in `create'
My code snippets are given below.
views/users/index.html.erb
<center>
<h1>Select your option</h1>
<p>
<%= link_to "Register here",users_new_path %>
</p>
<p>
<%= link_to "Display your data",users_show_path %>
</p>
</center>
views/users/new.html.erb
<h1>Enter your data</h1>
<center>
<%= form_for :user,:url => {:action => 'create'} do |f| %>
<% if @user.errors.any? %>
<div id="errorExplanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited
this post from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<p>
<%= f.label :Name %>
<%= f.text_field :name,placeholder:"Enter your name" %>
</p>
<p>
<%= f.label :Email %>
<%= f.email_field :email,placeholder:"Enter your email" %>
</p>
<p>
<%= f.label :content %>
<%= f.text_area :content %>
</p>
<p>
<%= f.submit "Create" %>
</p>
<% end %>
</center>
controller/users_controller.rb
class UsersController < ApplicationController
def index
end
def new
@user=User.new
end
def show
end
def create
@user=User.new(user_params)
if @user.save
flash[:notice]="User has created successfully"
flash[:color]="valid"
redirect_to :action => 'index'
else
flash[:alert]="User did not create"
flash[:color]="invalid"
render :new
end
end
private
def user_params
params.require(:user).permit(:name, :email,:content)
end
end
model/user.rb
class User < ActiveRecord::Base
attr_accessible :content, :email, :name
EMAIL_REGEX = /\A[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\z/i
validates :name, :presence => true, :uniqueness => true, :length => { :in => 3..20 }
validates :email, :presence => true, :uniqueness => true, :format => EMAIL_REGEX
end
When I click on create button I get the above error. Please help to solve this error.
Upvotes: 0
Views: 94
Reputation: 2396
It seems you have not configured strong_parameters.
You can find more info about it here https://github.com/rails/strong_parameters
Upvotes: 1