Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActionController::UrlGenerationError in Admin::Bids#show #4028

Closed
ericduvon opened this issue Jul 13, 2015 · 14 comments
Closed

ActionController::UrlGenerationError in Admin::Bids#show #4028

ericduvon opened this issue Jul 13, 2015 · 14 comments

Comments

@ericduvon
Copy link

I keep getting this error when trying to view the "show" page for a resource. I can view the "index" and "edit" pages okay though.

screen shot 2015-07-13 at 11 06 01 am

@timoschilling
Copy link
Member

Please provide the related resource file and the stacktrace.

@ericduvon
Copy link
Author

app/admin/bid.rb

ActiveAdmin.register Bid do

  permit_params :lot_id, :user_id, :amount

end
ActionView::Template::Error (No route matches {:action=>"edit", :controller=>"admin/bids", :format=>nil, :id=>#<Bid id: nil, lot_id: nil, user_id: nil, amount: 0, created_at: nil, updated_at: nil>} missing required keys: [:id]):
    1: insert_tag renderer_for(:show)
  vendor/bundle/gems/actionpack-4.1.6/lib/action_dispatch/journey/formatter.rb:39:in `generate'
  vendor/bundle/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:599:in `generate'
  vendor/bundle/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:629:in `generate'
  vendor/bundle/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:665:in `url_for'
  vendor/bundle/gems/actionpack-4.1.6/lib/action_dispatch/routing/url_for.rb:155:in `url_for'
  vendor/bundle/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:230:in `call'
  vendor/bundle/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:181:in `call'
  vendor/bundle/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:270:in `block (2 levels) in define_url_helper'

@timoschilling
Copy link
Member

Pleas provide a longer stacktrace, it should be go to the first active admin row

@ericduvon
Copy link
Author

Sorry, here it is:

vendor/bundle/gems/actionpack-4.1.6/lib/action_dispatch/journey/formatter.rb:39:in `generate'
vendor/bundle/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:599:in `generate'
vendor/bundle/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:629:in `generate'
vendor/bundle/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:665:in `url_for'
vendor/bundle/gems/actionpack-4.1.6/lib/action_dispatch/routing/url_for.rb:155:in `url_for'
vendor/bundle/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:230:in `call'
vendor/bundle/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:181:in `call'
vendor/bundle/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:270:in `block (2 levels) in define_url_helper'
vendor/bundle/gems/inherited_resources-1.6.0/lib/inherited_resources/url_helpers.rb:222:in `edit_resource_path'
vendor/bundle/gems/actionpack-4.1.6/lib/abstract_controller/helpers.rb:70:in `edit_resource_path'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element.rb:180:in `method_missing'
vendor/bundle/bundler/gems/activeadmin-aff21a4b4144/lib/active_admin/resource/action_items.rb:68:in `block in add_default_action_items'
vendor/bundle/bundler/gems/activeadmin-aff21a4b4144/lib/active_admin/views/action_items.rb:9:in `instance_exec'
vendor/bundle/bundler/gems/activeadmin-aff21a4b4144/lib/active_admin/views/action_items.rb:9:in `block (2 levels) in build'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/context.rb:92:in `with_current_arbre_element'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:26:in `build_tag'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:39:in `insert_tag'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:14:in `span'
vendor/bundle/bundler/gems/activeadmin-aff21a4b4144/lib/active_admin/views/action_items.rb:8:in `block in build'
vendor/bundle/bundler/gems/activeadmin-aff21a4b4144/lib/active_admin/views/action_items.rb:7:in `each'
vendor/bundle/bundler/gems/activeadmin-aff21a4b4144/lib/active_admin/views/action_items.rb:7:in `build'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:30:in `block in build_tag'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/context.rb:92:in `with_current_arbre_element'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:26:in `build_tag'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:39:in `insert_tag'
vendor/bundle/bundler/gems/activeadmin-aff21a4b4144/lib/active_admin/views/title_bar.rb:50:in `build_action_items'
vendor/bundle/bundler/gems/activeadmin-aff21a4b4144/lib/active_admin/views/title_bar.rb:24:in `block in build_titlebar_right'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/context.rb:92:in `with_current_arbre_element'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:26:in `build_tag'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:39:in `insert_tag'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:14:in `div'
vendor/bundle/bundler/gems/activeadmin-aff21a4b4144/lib/active_admin/views/title_bar.rb:23:in `build_titlebar_right'
vendor/bundle/bundler/gems/activeadmin-aff21a4b4144/lib/active_admin/views/title_bar.rb:10:in `build'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:30:in `block in build_tag'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/context.rb:92:in `with_current_arbre_element'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:26:in `build_tag'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:39:in `insert_tag'
vendor/bundle/bundler/gems/activeadmin-aff21a4b4144/lib/active_admin/views/pages/base.rb:69:in `build_title_bar'
vendor/bundle/bundler/gems/activeadmin-aff21a4b4144/lib/active_admin/views/pages/base.rb:51:in `block (2 levels) in build_page'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/context.rb:92:in `with_current_arbre_element'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:26:in `build_tag'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:39:in `insert_tag'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:14:in `div'
vendor/bundle/bundler/gems/activeadmin-aff21a4b4144/lib/active_admin/views/pages/base.rb:48:in `block in build_page'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/context.rb:92:in `with_current_arbre_element'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
vendor/bundle/bundler/gems/activeadmin-aff21a4b4144/lib/active_admin/views/pages/base.rb:47:in `build_page'
vendor/bundle/bundler/gems/activeadmin-aff21a4b4144/lib/active_admin/views/pages/base.rb:10:in `build'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:30:in `block in build_tag'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/context.rb:92:in `with_current_arbre_element'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:26:in `build_tag'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/element/builder_methods.rb:39:in `insert_tag'
vendor/bundle/bundler/gems/activeadmin-aff21a4b4144/app/views/active_admin/resource/show.html.arb:2:in `block in _vendor_bundle_bundler_gems_activeadmin_aff__a_b_____app_views_active_admin_resource_show_html_arb__4172034932502515480_70093171465420'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/context.rb:45:in `instance_eval'
vendor/bundle/gems/arbre-1.0.3/lib/arbre/context.rb:45:in `initialize'
vendor/bundle/bundler/gems/activeadmin-aff21a4b4144/app/views/active_admin/resource/show.html.arb:1:in `new'
vendor/bundle/bundler/gems/activeadmin-aff21a4b4144/app/views/active_admin/resource/show.html.arb:1:in `_vendor_bundle_bundler_gems_activeadmin_aff__a_b_____app_views_active_admin_resource_show_html_arb__4172034932502515480_70093171465420'

@timoschilling
Copy link
Member

On which url does this happen? On a Page or a Resource? Please provide the active admin file for the url.

@ericduvon
Copy link
Author

It happens on a url when trying to view a particular bid (resource), for example: http://localhost:3000/admin/bids/711

In my config/routes.rb file I have: ActiveAdmin.routes(self)

@seanlinsley
Copy link
Contributor

The only other person who's reported a UrlGenerationError (in #2652) said that it was a conflict with the routes gem. Are you using that, by chance?

@ericduvon
Copy link
Author

@seanlinsley Thanks for your response, but I am not using the routes gem.

@timoschilling
Copy link
Member

Please post the related model.

@ericduvon
Copy link
Author

class Bid < ActiveRecord::Base
  belongs_to :lot
  belongs_to :user

  #validate :check_if_highest_bid

  after_save :update_lot
  #after_save :notify_outbid
  #after_save :update_bidders
  after_save :update_lot_time
  #after_destroy :update_lot

  def auto_bid
    # these are the parameters passed to initialization of AutoBidder class
    # this_bidder: the user placing the current bid
    # bid: the current bid
    # @lot: the lot being bid on
    this_bidder = self.user
    bid = self
    @lot = self.lot

    # if the lot has no bids yet, save the current bid and set it as max bid
    # if this conditional is true, then this bid being placed is the initial bid
    if @lot.has_bids?
        # uses the AutoBidder class for complex logic involved in auto bidding
      autobidder = AutoBidder.new(@lot, this_bidder, bid)
      autobidder.place_bid
     # AuctionMailer.notify_bidder(this_bidder.email, @lot).deliver
    else
      new_max_bid = this_bidder.max_bids.create(amount: bid.amount, lot_id: @lot.id)
      @lot.max_bid = new_max_bid


      bid.amount = @lot.price + @lot.increment
      bid.save
    end
  end

  # checks if the high bidder is bidding when they're already the high bidder
  def repeat_bidder?
    user == lot.max_bid.user
  end

  def username
    user.email if user
  end

  def lot_name
    lot.title
  end

  def update_lot
    lot.check_highest_bid
  end

  def check_if_highest_bid
    errors.add(:amount, "must be higher than current bid") unless lot.price < amount
  end

  def update_lot_time
    if (lot.end_time - Time.now) <= lot.closing_window
      lot.end_time += lot.time_extension
      lot.save
    end
  end

  def notify_outbid
    @lot = lot
    @bids = lot.bids

      logger.debug "notify outbid"
      if @bids.count > 1
    @outbid = {user: @bids[-2].user, amount: @bids.last.amount, lot: @lot.title}
    AuctionMailer.you_got_outbid_playa(@outbid).deliver
      end
  end

  def bidders
    @bidders ||= []
  end

  def notify_all_bidders(bidders)
    bidders.each do |bidder|
      notify_bidder(bidder)
    end
  end

  def notify_bidder(bidder)
    AuctionMailer.notify_bidder(bidder, lot).deliver
  end

  def update_bidders
     lot.bids.each do |bid|
       bidders << bid.user.email
     end

       bidders.uniq!

       notify_all_bidders(bidders)

  end
end

@seanlinsley
Copy link
Contributor

You must be customizing your controller, because as your error shows:

ActionView::Template::Error (No route matches {
  :action=>"edit",
  :controller=>"admin/bids",
  :format=>nil,
  :id=>#<Bid id: nil, lot_id: nil, user_id: nil, amount: 0, created_at: nil, updated_at: nil>
} missing required keys: [:id])

The ID parameter is being passed an instance of the model, not a number.

The only other ticket with something similar is #2527, which does this in a test:

  it "assigns the requested blog to @blog" do
    @blog = FactoryGirl.create(:blog)
    get :show, id: @blog
    assigns(:blog).should eq(@blog) 
  end

When they should be doing get :show, id: @blog.id

@seanlinsley
Copy link
Contributor

It sounds pretty clearly like this is a bug in your code and not in Active Admin, so I'm closing this for now.

@HusseinElMotayam
Copy link

Faced the same issue with one particular model that has no primary keys at all. The Size model failed to render its index in Active Admin. The error was reported when rendering its route where the passed ID was an instance object of the Size model without an :id (which doesn't exist). See below:

ActionController::UrlGenerationError - No route matches {:action=>"show", :controller=>"admin/sizes", :format=>nil, :id=>#<Size garment_id: 2681, measurement_id: 32132, name: "00">} missing required keys: [:id]:

After adding primary key "id" for that model add_column :sizes, :id, :primary_key, the issue is no longer happening. Active Admin is now able to render the index page of the Size model normally.

Hope this helps.

@ghost
Copy link

ghost commented Apr 24, 2016

I got this same error in every listing page on my production server.

active_admin version : master branch, ref d84f819

Exception `ActionController::UrlGenerationError' at 
vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5.2/lib/action_dispatch/journey/formatter.rb:46 - No route matches {:action=>"index", :format=>:csv}
Exception `ActionView::Template::Error' at 
vendor/bundle/ruby/2.2.0/gems/actionview-4.2.5.2/lib/action_view/template.rb:310 - No route matches {:action=>"index", :format=>:csv}
Exception `ActionView::Template::Error' at /home/app/foo/foo/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5.2/lib/active_support/notifications/instrumenter.rb:23 - No route matches {:action=>"index", :format=>:csv}
Exception `ActionView::Template::Error' at /home/app/foo/foo/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5.2/lib/action_controller/metal/rescue.rb:32 - No route matches {:action=>"index", :format=>:csv}
Exception `ActionView::Template::Error' at /home/app/foo/foo/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5.2/lib/active_support/notifications/instrumenter.rb:23 - No route matches {:action=>"index", :format=>:csv}
Exception `ActionView::Template::Error' at /home/app/foo/foo/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/query_cache.rb:44 - No route matches {:action=>"index", :format=>:csv}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants