0

I want to trigger a put method for voting with emojis but button_to is not working with slim in rails

I have the following:

 = button_to vote_backend_session_path(@session.id, emoji: emoji), method: :put, remote: true, class: "btn btn-vote btn-xs bg-dark border-white hover-primary" do
      i.material-icons.align-middle. #{emoji.to_s}
      span.align-middle.text-white.ms-2 = @session.total(emoji)

it output the following in developer console:

enter image description here

So everytime a post action is triggered and my controller says it can't find the specified route.

I tried to change only in developer console to put, but then it triggers an GET instead of PUT

I looked at several questions regarding button_to:

I looked at the API doc as well here and was not able to find a solution.

So how to fix this and use button_to with rails in my case?

OuttaSpaceTime
  • 710
  • 10
  • 24

1 Answers1

1

your button type is submit, which will trigger the form to submit its fields

it shouldn't be inside a form tag you can use the CSS technique to make it look like inside the form

Saiqul Haq
  • 2,287
  • 16
  • 18
  • Can you further specify what you mean be the css technique, do you think using link_to might be a better approach? Since button_to created the form. I tried to use it because in some cases my vote action creates a new instance of the vote class – OuttaSpaceTime Dec 09 '21 at 16:59
  • I think it is not the problem because when I change to `post :vote` in routes everything is working fine – OuttaSpaceTime Dec 09 '21 at 19:35
  • yea using link_to is better, you can ignore the CSS technique (styling) that I said above – Saiqul Haq Dec 10 '21 at 02:42