Sending Records from a new View

Asked

Viewed 84 times

0

I created a new action knowledges on 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 Responsabilities and Knowledges tables.

I put the form_tag, because if I create the form_for it displays an error. But when I click on my send button, the Knowledges records that Responsability has, it says that 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 I need to do to get these records sent?

1 answer

2

Better you split that 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 placed 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 Routes.Rb something like.

resources :responsabilities do
  member do
    post 'edit'
  end  
end
  • Thanks @Felipe Bergamo. I implemented using : <%= form_tag responsability_path, method: :put do -%>. For the records of nested_knowledges worked. But I have 2 more nested_competencesand nested_tools. When I mark a knowledge it updates, but if I mark a competence it unchecks the knowledge. I thought it might be the parameters I put in my Controller, but apparently it’s not ,because when I was in _Form of the application worked normally.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.