File currently in error

The description of the baggage_params method, the description of the new action and the description of the create action may be those using build.

class Admin :: BaggagesController</pre>
<strong>Transition source file (admin/baggages/index.html.haml)</strong>
<pre><code>= search_form_for @search, url: admin_baggages_url do | f |
  = f.label: name_cont, "Enter your name"
  = f.search_field: name_cont
  = f.submit "search"
    % tr
      % th = sort_link (@search,: name) #result part and link
      % th = sort_link (@search,: address)
    [email protected] users.each do | user | #controller "@users = @ search.result" "returns" what you searched for
      % tr
        -#% td = link_to user.name, new_admin_baggage_url (@q,:'q [user_id_eq]'=>"# {user.id}")
        % td = user.name
        % td = user.address
        % td = link_to "New", new_admin_baggage_url (@q,:'q [user_id_eq]'=>"# {user.id}")
Transition destination file (admin/baggages/new.html.haml)

= f.hidden_field: user_id,: value =>In the line @q (params [: id]), the value cannot be passed to user_id and it is sent empty.

    = form_for @baggage, url: admin_baggages_path do | f |
          % span
            Luggage type
            = f.select: type, [["Namamono", "Namamono"], ["Chilled", "Chilled"], ["Frozen", "Frozen"], ["Other", "Other" ]], include_blank: "Please select"
          % span
            Storage period
            = f.text_field: storage_period, class: "baggage_text", placeholder:'Example) 7'
            % span days
          % span
            Tracking number
            = f.text_field: code, class: "baggage_text", placeholder: '123456789012'
      = f.hidden_field: user_id,: value =>@q (params [: id])<-No value passed in this part
      = f.submit'SEND', class: "baggage__send"

I put a<-mark next to the code where it was clearly not implemented.

  • Answer # 1

    Separate user types,current_userWhen you are an administrator, it is OK if you search the luggage of general users

    As an image

    if current_user.admin?
      @item = User.item.build

    Is it like that?

Related articles