Create action from a button?

Hello all.

I've got a model that basically records whever a user has completed an action. When it's created it auto fills in the user_id via sessions etc.

However I want to create links on the various actions, so users can just click them, eg navigating possible actions with a button for "complete!" and that will insert a value into the model for them.

<%= button_to "Complete!",user_actions_path,:action_id =>, :method => :post %>

This posts the page correctly, however it complains that the action/ action_id is null (as i'm using validations in the model to stop this. I've tried tweaking action_id to action and removing etc. But nothing works. Action id is a proper id too, but by the time rails gets to it it's null...

I have no idea how to fix this too?. Anyone got any clues?

1) Use `View Source` to inspect the rendered HTML to see what      values are set there.

2) Look at your Rails log to see exactly what's being submitted.

If that doesn't show you the problem, post the relevant parts of both those here.

Beau wrote in post #1015128:

<%= button_to "Complete!",user_actions_path,:action_id =>, :method => :post %>

This might seem trivial and persnickety, but please don't use punctuation in buttons, toolbar items or menus. The word "Complete" is not a sentence and doesn't deserve punctuation. The one exception to this rule is the use of the ellipsis to indicate that choosing the button or menu item will request further input from the user (e.g. a dialog/input box). "Open Recent..." for example.

:slight_smile: It doesn’t actually say that. I figured it was easier to change the text to represent an easier concept than the actual app.

I did discover that i need to pass the arguments in this way though. Rather than specifying :action_id=> id as a parameter, I needed to add it to the link.

Eg user_actions_path(:action_id=>id), :method=>:post

This of course still didn’t enter it in correctly, but I could read :action_id out in the controller. Looking at the controller code it was reading the param :action out.

So the way to call this is.

user_actions_path(:action=>{:action_id => id})

So now I can post all the data by working it out from the page. I’m surprised the information to do this was so hard.