Sending Records for a New View

0

I created a new action knowledges in my controller responsabilities and created a view called nested_knowledges . I made the action render this view. I put the following code in this view:

    <%= form_tag edit_responsability_path do -%>
            <% for @responsability in Responsability.find(:all)-%>
                <% for knowledge in Knowledge.find(:all) %>
                    <%= check_box_tag "responsability[knowledge_ids][]", knowledge.id, @responsability.knowledges.include?(knowledge)  %>
                    <%= knowledge.nome %>
                    <br/>
                <% end %>
            <% end %>
<div class="actions">
    <%= submit_tag l(:send) %>
    <br/>
</div>

It renders a has_and_belongs_to_many relationship between the Responsibilities and Knowledges tables.

I put form_tag, because if I create form_for it displays an error. But when I click on my button to send, the Knowledges records that that Responsability has, it says there is no route, as in the error below:

Started POST "/responsabilities/1/edit" for 127.0.0.1 at 2014-06-03 12:00:24 -0300

ActionController::RoutingError (No route matches [POST] "/responsabilities/1/edit"):
  actionpack (3.2.13) lib/action_dispatch/middleware/debug_exceptions.rb:21:in 'call'
  actionpack (3.2.13) lib/action_dispatch/middleware/show_exceptions.rb:56:in 'call'
  railties (3.2.13) lib/rails/rack/logger.rb:32:in 'call_app'
  railties (3.2.13) lib/rails/rack/logger.rb:16:in 'block in call'
  activesupport (3.2.13) lib/active_support/tagged_logging.rb:22:in 'tagged'
  railties (3.2.13) lib/rails/rack/logger.rb:16:in 'call'
  actionpack (3.2.13) lib/action_dispatch/middleware/request_id.rb:22:in 'call'
  rack (1.4.5) lib/rack/methodoverride.rb:21:in 'call'
  rack (1.4.5) lib/rack/runtime.rb:17:in 'call'
  activesupport (3.2.13) lib/active_support/cache/strategy/local_cache.rb:72:in 'call'
  rack (1.4.5) lib/rack/lock.rb:15:in 'call'
  actionpack (3.2.13) lib/action_dispatch/middleware/static.rb:63:in 'call'
  railties (3.2.13) lib/rails/engine.rb:479:in 'call'
  railties (3.2.13) lib/rails/application.rb:223:in 'call'
  rack (1.4.5) lib/rack/content_length.rb:14:in 'call'
  railties (3.2.13) lib/rails/rack/log_tailer.rb:17:in 'call'
  rack (1.4.5) lib/rack/handler/webrick.rb:59:in 'service'
  c:/Ruby193/lib/ruby/1.9.1/webrick/httpserver.rb:138:in 'service'
  c:/Ruby193/lib/ruby/1.9.1/webrick/httpserver.rb:94:in 'run'
  c:/Ruby193/lib/ruby/1.9.1/webrick/server.rb:191:in 'block in start_thread'

What do I need to do to get these records sent?

    
asked by anonymous 03.06.2014 / 17:02

1 answer

2

You better split this question, you have several questions together in one question.

But, answering the Routes error

If you included in your route.rb the following line

resources :responsabilities

You have a list of pre-generated routes, in which case you have put the following path in your form_tag

edit_responsability_path

This path does not have a POST method. will generate something from tp / respo ../ {id} / edit

If you want to access the controller update method, I suggest doing

<%= form_tag responsability_path, method: :put do -%>

Or if you want to access this route with a post you have to put in the routes.rb something like.

resources :responsabilities do
  member do
    post 'edit'
  end  
end
    
04.06.2014 / 00:40