ruby on rails - Can't pass project.id from view to controller -



ruby on rails - Can't pass project.id from view to controller -

i want pass current project's id tickets controller (creating ticket project), seek below. however, way below gives me next link:

tickets/new?project_id=8

...when want way:

tickets/new

...even though want project_id accessible in controller.

how can this? clearify: don't want project_id part of url, want pass (in way) parameter controller.

from view:

<h1><%= @project.title %></h1> <-- project's attributes reachable here <%= link_to "create ticket", new_ticket_path(:project_id => @project.id), :class => "btn edit_button" %>

tickets controller:

1. class ticketscontroller < applicationcontroller 2. def new 3. @ticket = ticket.new 4. @id = params[:project_id] 5. 6. @project = project.find(@id) 7. end 8. end

the route link_to points looks following:

new_ticket /tickets/new(.:format) tickets#new

if tickets belong project, might want consider nesting resources.

right now, routes this:

resources :projects resources :tickets

this generates routes /projects/new , /tickets/new. can instead this:

resources :projects resources :tickets end

this give routes /projects/8/tickets/new. link new ticket doing new_project_ticket_path(@project). actual form of route generate is: /projects/:project_id/tickets/:id. params[:project_id] give id of project.

ruby-on-rails database ruby-on-rails-3 view controller

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -