0

my controller:

class SkyscraperApplicationsController < ApplicationController

def new
 @skyscraper=SkyscraperApplications.new(skyscraper_params)
 if @skyscraper.save
    redirect_to "/skyscraper_applications/new", :notice => t("skyscraper_saved")

else
 redirect_to "/skyscraper_applications/new", :notice => t("skyscraper_failed")

end 
end
 private 
def skyscraper_params
  params.require(:skyscraper_applications).permit(:name, :employee_count, :usecase, :email_admin, :what_you_do)
 end

end

my form in skyscraper_applications/new.html.erb:

<form class="form-horizontal">
        <%= simple_form_for @skyscraper do |f| %>
      <div class="control-group">
        <label class="control-label" for="name"><%=t ".company_name"%></label>
        <div class="controls">
          <div><%= f.input :name, :label=>false %></div>
        </div>
      </div>
      <div class="control-group">
        <label class="control-label" for="employees"><%=t ".no_of_employees"%></label>
        <div class="controls">
          <div><%= f.input :employee_count, :label=>false %></div>
        </div>
      </div>
      <div class="control-group">
        <label class="control-label" for="employees"><%=t ".usecase"%></label>
        <div class="controls">
          <%= f.select :usecase, options_for_select([["Select One", ""], "CAD/Render", "Video Production/Editing", "Music Production", "Game Design", "Email/Web", "Other"])%>
        </div>
      </div>
      <div class="control-group">
        <label class="control-label" for="Administrator"><%=t ".admin_email"%></label>
        <div class="controls">
          <div><%= f.input :email_admin, :label=>false %></div>
        </div>
      </div>
      <div class="control-group">
        <label class="control-label" for="Administrator"><%=t ".what_you_do"%></label>
        <div class="controls">
        <div><%= f.input :what_you_do, :label=>false, :as => :text, :input_html => { :rows => 4 }%></div>
      </div>
      </div>
      <div class="control-group">
        <div class="controls">
          <div class="test-drive-submit"><%= f.button :submit, t(".submit")%></div>
        </div>
      </div>
    </form>
    <%end%>

So I am not sure why i am getting this error because :skyscraper_applications is in my schema add all the fields are correct. I feel like my method and my simple_form_for is all good. Am I doing something wrong with strong params? Thanks in advance!

1 Answers1

0

The error is just saying that params[:skyscraper_applications] is empty or missing.

I believe Rails would use the singular form in this case (easily confirmable by looking at the generated HTML or the parameters submitted) so you should be doing params.require(:skyscraper_application).pemit(...)

Your class name is plural, which rails won't have been expecting - the rails inflection will have stripped the "s" from the end.

In addition, using the new action as you are is wrong - it's normal to arrive at the new action with no parameters since that's how you get to see the form. You seem to be combining the create and the new actions which on top of this looks like you'd get an infinite redirect loop were it not for the current error: no matter what the outcome of the save you redirect back to new (which will redirect again).

You should move your code for instantiating and saving records to the create action.

Frederick Cheung
  • 83,189
  • 8
  • 152
  • 174