I have a controller messages which for the index action lists
messages. I want buttons to be able to serve actions “mark_read” and
“delete”.
how do i create my form to be able to submit the buttons without it
redirecting to the create action for my controller ?
chubbs
If I understood you correctly, “by clicking mark read”, it should
update a mark_read boolean field to be true instead of false, in that
case you can set your form to go to PUT process (update action
method), and for delete you can still go to DELETE process (destroy
action method) in your controller. But my solution here is involving
two forms for each of your record inside your object listing
iteration. cos I don’t see the reason why combine them in one.
ex.
form_tag book_path(book), :method => :put do
hidden_field_tag :mark_read, :value => “1”
end
and
form_tag book_path(book), :method => :delete do
hidden_field_tag :id, :value => book.id
end
def inbox_action
case params[:submit]
when ‘Delete’
destroy #destroy action
when ‘Mark Read’
if(params[:select])
selected_pms = @current_user.user_privmsgs.find(params[:select])
for pm in selected_pms
pm.is_unread = false
pm.save
end
end
end
redirect_to privmsgs_url
end
bit confused how this works with using rest, so i dont it that way.
dunno if its a good way to do it tho.
chubbs
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.