Note that there are some explanatory texts on larger screens.

plurals
  1. POForm submit button is calling controller's index function
    primarykey
    data
    text
    <p>The author built a UPS scaffold and rails created the model as <code>up</code> instead of <code>ups</code>. I've hacked some solutions in to make it work, but I can't get the create method to work when called from the new form. Rails calls the index function and no new object is created. </p> <p><strong>ups_controller.rb</strong></p> <pre><code>def create @up = Ups.new(params[:up]) respond_to do |format| if @up.save format.html { redirect_to @up, notice: 'Up was successfully created.' } format.json { render json: @up, status: :created, location: @up } else format.html { render action: "new" } format.json { render json: @up.errors, status: :unprocessable_entity } end end end def new @up = Ups.new respond_to do |format| format.html # new.html.erb format.json { render json: @up } end end </code></pre> <p><strong>ups/form.html.erb</strong></p> <pre><code>&lt;%= form_for(@up) do |f| %&gt; &lt;table class="table table-striped table-bordered"&gt; &lt;tr&gt; &lt;th&gt;name&lt;/th&gt; &lt;td&gt;&lt;%= f.text_field :name %&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt;attr&lt;/th&gt; &lt;td&gt;&lt;%= f.select :attr_id, options_from_collection_for_select(Attr.order(:name).where(:major =&gt; true).all, "id", "name", @up.attr_id) %&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt;Action&lt;/th&gt; &lt;td&gt;&lt;%= f.submit "Submit New UPS" %&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;% end %&gt; </code></pre> <p><strong>routes.rb</strong></p> <pre><code> resources :ups match 'ups/create' =&gt; 'ups#create' match 'ups/index' =&gt; 'ups#index' match 'pdus/link_all_ups' =&gt; 'pdus#link_all_ups' </code></pre> <p><strong>Here is the button that calls the new method of the ups_controller:</strong></p> <pre><code>&lt;%= link_to 'Enter New UPS', new_ups_path, :class =&gt; "btn btn-success pull-right" %&gt; </code></pre> <p><strong>rake routes</strong></p> <pre><code> ups GET /ups(.:format) ups#index POST /ups(.:format) ups#create new_up GET /ups/new(.:format) ups#new edit_up GET /ups/:id/edit(.:format) ups#edit up GET /ups/:id(.:format) ups#show PUT /ups/:id(.:format) ups#update DELETE /ups/:id(.:format) ups#destroy ups_index /ups/index(.:format) ups#index </code></pre> <p>Thanks for any advice.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload