Controller::UrlGenerationError

93 views
Skip to first unread message

Aspiring.Student.programmer

unread,
Oct 20, 2014, 6:56:19 PM10/20/14
to rubyonra...@googlegroups.com
Hey

I am adding another database to my first one and i created the html to work showing the data but when i want to create a new entry this error occurs. I have a new controller with everything in it but not sure why it doesnt work.


ActionController::UrlGenerationError in Shopping#new

Showing C:/Sites/blog/app/views/shopping/new.html.erb where line #2 raised:

No route matches {:action=>"show", :controller=>"shopping"} missing required keys: [:id]

Extracted source (around line #2):

1
2
3
4
5
          
<h1>Shopping#new</h1>
<%= form_for @shop, url: shopping_path do |f| %>
<p>
<%= f.label :title %><br>
<%= f.text_feild :title %>

Rails.root: C:/Sites/blog

Application Trace | Framework Trace | Full Trace
app/views/shopping/new.html.erb:2:in `_app_views_shopping_new_html_erb___572466137_45190848'

Request

Parameters:

None

Response

Headers:

None


Controller:


class ShoppingController < ApplicationController
def new

@shop = Shop.new

end

def create
@shop = Shop.new(shop_params)

@shop.save
redirect_to @shop
end

def show
@shop = Shop.find(params[:id])
end

def index
@shopping = Shop.all
end




private
def shop_params
params.require(:shop).permit(:title, :text)
end

end


HTML FILE

<h1>Shopping#new</h1>
<%= form_for @shop, url: shopping_path do |f| %>
<p>
<%= f.label :title %><br>
<%= f.text_feild :title %>
</p>

<p>
<%= f.label :text %><br>
<%= f.text_area :text %>
</p>

<p>
<%= f.submit %>
</p>

<% end %>
<%= link_to 'Back', shopping_path %>





Regards




Colin Law

unread,
Oct 21, 2014, 3:54:39 AM10/21/14
to rubyonra...@googlegroups.com
On 20 October 2014 23:56, Aspiring.Student.programmer <sabri...@gmail.com> wrote:
Hey

I am adding another database to my first one and i created the html to work showing the data but when i want to create a new entry this error occurs. I have a new controller with everything in it but not sure why it doesnt work.

Do you mean a new table, rather than a new database?
 


ActionController::UrlGenerationError in Shopping#new

Showing C:/Sites/blog/app/views/shopping/new.html.erb where line #2 raised:

No route matches {:action=>"show", :controller=>"shopping"} missing required keys: [:id]

Extracted source (around line #2):

1
2
3
4
5
<h1>Shopping#new</h1>
<%= form_for @shop, url: shopping_path do |f| %>

Can you post the file db/schema.rb please.

By the way, it is generally better to copy/paste the error from the terminal window rather than post the html.  It should also be in development.log.

Colin
 

Aspiring.Student.programmer

unread,
Oct 25, 2014, 12:32:34 AM10/25/14
to rubyonra...@googlegroups.com
here is the  schema


ActiveRecord::Schema.define(version: 20141016020227) do

  create_table "articles", force: true do |t|
    t.string   "title"
    t.text     "text"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "time"
    t.string   "age"
    t.string   "el"
    t.string   "experience"
  end

  create_table "shops", force: true do |t|
    t.string   "title"
    t.text     "text"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

end

and yeah i meant new table. 

Jason Fleetwood-Boldt

unread,
Oct 26, 2014, 10:00:07 AM10/26/14
to rubyonra...@googlegroups.com

I think you need to put the url parameter in the form like this:

 shopping_path(@shop)


I think you can also omit the URL parameter entirely and the form_for will know which path to use automatically because you have supplied the object that the form is bound to. (I am 95% sure I am correct so leave 5% room for error in this information)

-Jason


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/d6758e06-1573-4431-9b82-87169d4ed426%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

----

Jason Fleetwood-Boldt

All material © Jason Fleetwood-Boldt 2014. Public conversations may be turned into blog posts (original poster information will be made anonymous). Email ja...@datatravels.com with questions/concerns about this.

Reply all
Reply to author
Forward
0 new messages