Jump to content

The ultimate community for Ruby on Rails developers.


Date handling in Controller .permit function

  • Please log in to reply
No replies to this topic

#1 javasauce



  • Members
  • 1 posts

Posted 12 October 2013 - 11:52 AM

Hi everyone,


I'm pretty new to ruby and rails, and this is the only snag I've run into where endlessly searching the internet has yielded nothing in terms of a solution.  Some background:



All I'm trying to do is have a user register an account successfully.  It throws an error saying that "birthdate(2i), birthdate(1i) and birthdate(3i) are unpermitted parameters."  This is the view where the user enters their information.

<h1> Create an Account </h1>

<h3 align="right"><%= link_to "Home", root_path %></h3>

<%= form_tag({controller: "users", action: "create"}, action: "/users", method: "post") do %>
  <%= label_tag(:username, "Username") %>
  <%= text_field(:user, :username) %>
  <br />

  <%= label_tag(:password, "Password") %>
  <%= password_field(:user, :password) %>
  <br />

  <%= label_tag(:birthdate, "Date of Birth") %>
  <%= date_select(:user, :birthdate, start_year: 1900, use_two_digit_numbers: true, order: [:month, :day, :year]) %>
  <br />

  <%= label_tag(:gender, "Gender") %>
  <%= radio_button(:user, :gender, "M") %>
  <%= label_tag(:genderM, "M") %>
  <%= radio_button(:user, :gender, "F") %>
  <%= label_tag(:genderF, "F") %>
  <br />

  <%= label_tag(:email, "E-mail Address") %>
  <%= email_field(:user, :email) %>
  <br />

  <%= submit_tag("Register") %>
<% end %>

Next, the controller:

def create

 # @clean_dob = params[:user]['birthdate(1i)'] + params[:user]['birthdate(2i)'] + params[:user]['birthdate(3i)']

 # puts params[:user]

  @user = User.new(params[:user].permit(:username, :password, :gender, :email, :birthdate => [:month, :day, :year]))

  if @user.save
    redirect_to users_path
    render 'register'

I've tried a few different things attempting to get .permit to accept the birthdate field, none of which worked.  Any guidance at all would be greatly appreciated.



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users