ruby on rails - nestled resources and form_for -
i have form inside of project view allows user give money project. have set nestled resources associate each payment appropriate project. having trouble submitting form correct path. in routes.rb have this:
resources :projects resources :payments, only: [:new, :create, :show] end
the form looks this:
<div class="container"> <div class="row row one"> <div class="col-sm-12 col-md-10"> <%= form_for [@projects, @payments] , method: 'post' %> <%= label_tag("first name") %><br> <%= text_field(:user, :first_name, class: 'form-control', :required => true) %><br> <%= label_tag("last name") %><br> <%= text_field(:user, :last_name, class: 'form-control', :required => true) %><br> <%= label_tag("card number") %><br> <%= text_field(:user, :cc_num, class: 'form-control', :required => true)%><br> <%= label_tag("expiration month") %><br> <%= text_field(:user, :exp_month, class: 'form-control', :required => true)%> <%= label_tag("expiration year") %><br> <%= text_field(:user, :exp_year, class: 'form-control', :required => true)%> <%= label_tag("amount") %><br> <%= text_field(:user, :amount, class: 'form-control', :required => true)%> <%= hidden_field_tag :user_id, :value => current_user.id , class: 'form-control'%> <%= hidden_field_tag :project_id, :value => @project.id , class: 'form-control'%> <%= submit_tag("sign up") %> <% end %> </div> </div> <!-- <div class="row"></div> -->
i have tried wrapping array in parentheses, , have tried:
<% form_for @projects, :url => {:action => 'create', :id => @project.id }, :html => { :method => :post } |f| %>
as have seen suggested in other threads not working me. rake routes shows path should be:
project_payments post /projects/:project_id/payments(.:format) payments#create
the error is:
no route matches [post] "/projects/1"
how should routing form? thanks!
the head of form needed more explicit in case:
<%= form_for [@project, @payment], url: project_payments_path(@project.id) , method: 'post' %>
Comments
Post a Comment