Ruby on Rails Thursday, May 12, 2016

I really dont know how begin, I have a form in my view (solicit.html.erb) where do iterate in each elements, each element have a radio button, input field and a button for create. When click on button, generate a new portability with date save this. this is my code

<% if params[:search_func_register].present? %>
  <h4><b>Results</b></h4>
    <%= form_tag(@portability, name: 'form', method: :get) do %>
      <table>
        <thead>
          <tr>
            <th>&nbsp;</th>
            <th>Nº contract</th>
            <th>New parcel</th>
            <th>Action</th>
          </tr>
        </thead>
        <tbody>
          <% @authorizations.each do |authorization| %>
            <tr>
              <td><%= radio_button_tag 'authorization', authorization.number_contract %></td>
              <td><%= authorization.number_contract %></td>
              <td>
                <input placeholder="Enter" type="text" name="portability_new_parcel" id="portability_new_parcel">
              </td>
              <td><%= link_to "Request", new_portability_path %></td>
            </tr>
          <% end %>
        </tbody>
      </table>
    <% end %>
<% end %>


I just create a new portability with this values on form... (id, new_parcel)

Contract_number is readonly for show what is the authorization that is doing this portability.

My portabilities_controller is:

 def index
    if params[:search_func_register]
      @employee = Employee.where(register: params[:search_func_register]).includes(:authorizations)
    else
      @portabilities = Portability.all
    end
  end
  def solicit
    if params[:search_func_register]
      @employee = Employee.where(register: params[:search_func_register]).includes(:authorizations)
      @authorizations = Authorization.where(employee_id: @employee)
      @portability = Portability.new
    else
      @authorizations = Authorization.all
    end
  end


But all this return this error when click on button Request:

undefined method `model_name' for nil:NilClass

I guess that create a other page for new portability is the solution. My route is:

resources :portabilities, except: :destroy do
    collection do
      get 'solicit'
    end
  end

Any idea about this, some tips? See ya!!

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/7a5da3ae-af8e-49d0-985e-9edb00f02404%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment