Using button_to to create new record in database, error: param is missing or the value is empty

Sean Stevens

I am trying to create a very basic button_to that will create a new record in the database. At the moment, I am hard coding in the 'video_id'. However, I am getting the following error:

param is missing or the value is empty: track

Request

Parameters:

{"authenticity_token"=>"e60ap2UFOpyfCLPrqRpvYCyZrfQwZ8DtmBglYu4n",
 "video_id"=>"1"}

My create method in my 'Tracks' controller looks like this:

def create
   Track.create(track_params)
   redirect_to root_path
end

def track_params
   params.require(:track).permit(:video_id)
end

My button_to in my application.html.erb looks like this

<%= button_to 'Save track', {:controller => "tracks", :action => "create", :video_id => "1" } , :method=>:post %>

Any help would be gratefully appreciated as I've been banging my head trying to solve this error for quite a while. To put things in context, what I ultimately want to achieve is the following solution: User searches for a keyphrase (a music video), which queries the Youtube API and displays the top 3 results. The user can then click the 'Save track' button to save the video_id of one of the three youtube videos to the track database. I've got up to the point where I can display the videos and now I'm trying to add this button.

Thanks in advance

Зелёный

Your problem in <%= button_to 'Save track', {:controller => "tracks", :action => "create", :video_id => "1" } , :method=>:post %>

this is not good way to build form (button_to generates a form containing a single button that submits to the URL created by the set of options.)

if you still want use button_to helper try pass simple path with params:

<%= button_to 'Save track', "/tracks/create?video_id=5"  , :method=>:post %>
                           ^^^^^^^^^|^^^^^^|^^^^^^^^^^
                          controller|action|params

this should generates html like this:

<form action="/tracks/create?video_id=5" class="button_to" method="post">
  <div>
    <input type="submit" value="Save track">
    <input name="authenticity_token" type="hidden" value="dUZL6a3NmlEZK9aVPEKX4rTxj/dTH2ZeBw1vCybWI8w=">
  </div>
</form>

Permit params:

def create
   Track.create(params.permit(:video_id))
   redirect_to root_path
end

Rails way for your case it is use _path helper and link_to helper.

Happy hacking.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Using button_to to create new record in database, error: param is missing or the value is empty

From Dev

param is missing or the value is empty error

From Dev

Rails 4 error "param is missing or the value is empty:" in create

From Dev

Param is missing or the value is empty: within new

From Dev

rails error - param is missing or the value is empty: buyer

From Dev

Rails : error param is missing or the value is empty : annonce

From Dev

Getting "Param is missing or the value is empty: user" error

From Dev

param is missing or the value is empty

From Dev

param is missing or the value is empty?

From Dev

param is missing or the value is empty for:

From Dev

Ajax request causing "param is missing or the value is empty" error

From Dev

Error "param is missing or the value is empty: personas_x_tipos_persona"

From Dev

Error "param is missing or the value is empty: personas_x_tipos_persona"

From Dev

Ransack Search Error: param is missing or the value is empty: profile

From Dev

ROR5: 'param is missing or the value is empty' error with adding Bookmarks

From Dev

param is missing or the value is empty error with patch link_to

From Dev

ParameterMissing param is missing or the value is empty

From Dev

param is missing or the value is empty for: quotes

From Dev

param is missing or the value is empty: user

From Dev

Param is missing or the value is empty for: contact

From Dev

param is missing or the value is empty: center

From Dev

param is missing or the value is empty on creation

From Dev

param is missing or the value is empty: comment

From Dev

Param is missing or the value is empty ROR

From Dev

param is missing or the value is empty: breads

From Dev

param is missing or the value is empty: conversation

From Dev

param is missing or the value is empty: sale

From Dev

param is missing or the value is empty when trying to update using active resource

From Dev

undefined value for empty database record

Related Related

  1. 1

    Using button_to to create new record in database, error: param is missing or the value is empty

  2. 2

    param is missing or the value is empty error

  3. 3

    Rails 4 error "param is missing or the value is empty:" in create

  4. 4

    Param is missing or the value is empty: within new

  5. 5

    rails error - param is missing or the value is empty: buyer

  6. 6

    Rails : error param is missing or the value is empty : annonce

  7. 7

    Getting "Param is missing or the value is empty: user" error

  8. 8

    param is missing or the value is empty

  9. 9

    param is missing or the value is empty?

  10. 10

    param is missing or the value is empty for:

  11. 11

    Ajax request causing "param is missing or the value is empty" error

  12. 12

    Error "param is missing or the value is empty: personas_x_tipos_persona"

  13. 13

    Error "param is missing or the value is empty: personas_x_tipos_persona"

  14. 14

    Ransack Search Error: param is missing or the value is empty: profile

  15. 15

    ROR5: 'param is missing or the value is empty' error with adding Bookmarks

  16. 16

    param is missing or the value is empty error with patch link_to

  17. 17

    ParameterMissing param is missing or the value is empty

  18. 18

    param is missing or the value is empty for: quotes

  19. 19

    param is missing or the value is empty: user

  20. 20

    Param is missing or the value is empty for: contact

  21. 21

    param is missing or the value is empty: center

  22. 22

    param is missing or the value is empty on creation

  23. 23

    param is missing or the value is empty: comment

  24. 24

    Param is missing or the value is empty ROR

  25. 25

    param is missing or the value is empty: breads

  26. 26

    param is missing or the value is empty: conversation

  27. 27

    param is missing or the value is empty: sale

  28. 28

    param is missing or the value is empty when trying to update using active resource

  29. 29

    undefined value for empty database record

HotTag

Archive