Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Kian Chakamian
Kian Chakamian
15,410 Points

I don't have a param key. How do I either work around it or set one up.

I don't have a key for my params so when it asks for a key in params.require(), I am not sure what to put. Can someone tell me either how to get around it or set one up?

Here is new.html.erb:

<%= simple_form_for @postings1314 do |r| %>
  <div>
    <%=r.label :firstName%>
    <%=r.text_field :firstName%>
  </div>

  <div>
    <%=r.label :lastName%>
    <%=r.text_field :lastName%>
  </div>

  <div>
    <%=r.label :age%>
    <%=r.text_field :age%>
  </div>

  <div>
    <%=r.label :bio%>
    <%=r.text_field :bio%>
  </div>

  <div>
    <%=r.submit%>
  </div>
<%end%>

Here is my grouponepostings_controller.rb:

class GrouponepostingsController < ApplicationController
  def index
    @postings1314 = Grouponepage.all
  end
  def show
    @posting1314singular = Grouponepage.find(params[:id])
  end
  def new
    @postings1314 = Grouponepage.new
  end
  def create
    page_params = params.require().permit(:firstName, :lastName, :age, :bio)
    @posting1314 = Grouponepage.new(page_params)
    @posting1314.save
    redirect_to '/grouponepostings'
  end
end

2 Answers

Trevor J
seal-mask
.a{fill-rule:evenodd;}techdegree
Trevor J
Python Web Development Techdegree Student 2,107 Points

You should have params.require(:grouponepage) Or the name of your model for talking to the database

class GrouponepostingsController < ApplicationController

  def create
    #  page_param should go in private, see below
    page_params = params.require().permit(:firstName, :lastName, :age, :bio)
  end

  private
    def page_params
      page_params = params.require(:grouponepage).permit(:firstName, :lastName, :age, :bio)
    end

end
Kian Chakamian
Kian Chakamian
15,410 Points

That worked perfectly. Thank you for your help. I will also be putting my create in private.