Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Pass param to controller #209

Closed
pawlarius opened this issue Apr 25, 2017 · 9 comments
Closed

Pass param to controller #209

pawlarius opened this issue Apr 25, 2017 · 9 comments
Assignees
Labels

Comments

@pawlarius
Copy link

How to pass parameter from form in datatable.rb?
screen shot 2017-04-25 at 11 11 18 am

I keep getting error : undefined method `[]' for nil:NilClass
I checked the params somehow always return to nil

Is there any specific way to pass params in this?
i tried #59 (comment)

@ajahongir
Copy link
Collaborator

@pawlarius
Copy link
Author

im sorry,could you be more exact ? kinda confused ..

i tried this in my post_datatable.rb
screen shot 2017-04-25 at 2 48 11 pm

and got this undefined method error..
screen shot 2017-04-25 at 2 47 49 pm

@pawlarius
Copy link
Author

@ajahongir

@ajahongir
Copy link
Collaborator

well, you a tring to user view_context in datatable which is not possible becase the context is available on in controller.

@pawlarius
Copy link
Author

pawlarius commented Apr 26, 2017

@ajahongir
i tried in controller but cause the same error
screen shot 2017-04-26 at 1 56 38 pm
am i doing it right..?

what im trying to do is, pass params with hidden field from method data in post_datatable.rb
screen shot 2017-04-26 at 1 57 18 pm

@n-rodriguez n-rodriguez self-assigned this May 12, 2017
@hermesalexis
Copy link

You can try to do form from a helper method and add to datatable .rb file whit a delegator

@n-rodriguez
Copy link
Member

What you want here is Rails button_to helper method : https://apidock.com/rails/ActionView/Helpers/UrlHelper/button_to. But anyway use it is a Draper decorator (https://github.com/drapergem/draper) so in the Datatable class you can do :

def data
  records.map do |record|
    {
      foo: record.decorate.name
      bar: record.decorate.publish_button
    }
  end
end

@n-rodriguez
Copy link
Member

BTW, remove datatable = PostDatatable.new... from post_datatable.rb.
This is how it works : https://github.com/jbox-web/ajax-datatables-rails#setup-the-controller-action

@n-rodriguez
Copy link
Member

Also it won't work if you're using Rails in API mode : #240

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants