Routing Problem

Relatively new to Ruby on Rails, i’m currently getting this routing
error I get after going to:- http://localhost:3000/licenses :-

No route matches {:controller=>“licenses”, :action=>“csv_import”}

My current routes.rb file:-

Inventory::Application.routes.draw do
root :to => “home#index”

ActiveAdmin.routes(self)

devise_for :admin_users, ActiveAdmin::Devise.config

resources :licenses
end

On Nov 28, 2011, at 10:52 AM, Derrick B. wrote:

ActiveAdmin.routes(self)

devise_for :admin_users, ActiveAdmin::Devise.config

resources :licenses
end

Try this:

resources :licenses do
collection do
post ‘csv_import’
end
end

That’s off the top of my head, but it should help. resources :licenses
just gets you the 7 RESTful actions, anything else you need to add
yourself, or use a wildcard map (haven’t seen one of those in quite a
while).

Walter

On 28 November 2011 15:52, Derrick B. [email protected] wrote:

ActiveAdmin.routes(self)

devise_for :admin_users, ActiveAdmin::Devise.config

resources :licenses

If you make this
resource :licenses do
member do
get ‘csv_import’
end
end

That will add the action csv_import as a GET operation to the routes.
It may well be that you don’t want it to be a GET however, but that is
a different issue.

See the Rails Guide on routing for more information.

Colin

On 28 November 2011 16:56, Derrick B. [email protected] wrote:

yourself, or use a wildcard map (haven’t seen one of those in quite a
while).

Walter

Thanks this has fixed the problem, but index.html.erb doesn’t display my
import csv file button, the code i have in index.html.erb:-

I suggest starting a new thread for this as it is nothing to do with
the subject line. In the meantime have a look at the generated html
(View > Page Source or similar in the browser) and see whether your
erb is generating the correct html.

Colin

Walter D. wrote in post #1034132:

On Nov 28, 2011, at 10:52 AM, Derrick B. wrote:

ActiveAdmin.routes(self)

devise_for :admin_users, ActiveAdmin::Devise.config

resources :licenses
end

Try this:

resources :licenses do
collection do
post ‘csv_import’
end
end

That’s off the top of my head, but it should help. resources :licenses
just gets you the 7 RESTful actions, anything else you need to add
yourself, or use a wildcard map (haven’t seen one of those in quite a
while).

Walter

Thanks this has fixed the problem, but index.html.erb doesn’t display my
import csv file button, the code i have in index.html.erb:-

Listing licenses

<% @licenses.each do |license| %>

<% end %>
App Serial User Notes
<%= license.app %> <%= license.serial %> <%= license.user %> <%= license.notes %> <%= link_to 'Show', license %> <%= link_to 'Edit', edit_license_path(license) %> <%= link_to 'Destroy', license, confirm: 'Are you sure?', method: :delete %>

<% form_for :dump, :url=>{:controller=>“licenses”,
:action=>“csv_import”}, :html => { :multipart => true } do |f| -%>
<table">

Select a CSV File : <%= f.file_field :file -%> <%= submit_tag 'Submit' -%> <% end -%>

<%= link_to ‘New License’, new_license_path %>

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs