-1

I guess this goes to the fundamentals of rails. Is it possible for me to simple have a checkbox and a submit button without it being tied to a model?

I found that most Rails example out there are using form_for and this needs to be bound to a particular model. Can I just send a boolean parameter to a particular controller without having to be bound to a particular model? I just want to send a boolean value to a controller.

I am having trouble finding examples for this particular format, especially using slim.

user1584575
  • 731
  • 3
  • 10
  • 20

2 Answers2

4

in Controller

class MyController
  def create
    @flag = params[:flag]
  end
end

in View

= form_tag '/mycontroller', method: :post do
  = check_box_tag 'flag', true, @flag
  = submit_tag 'Save'
solid
  • 66
  • 1
1

Yes you can, use form_tag instead of form_for http://apidock.com/rails/ActionView/Helpers/FormTagHelper/form_tag

So for your checkbox example you need

<%= form_tag('/posts/1', method: :put) do %>
  <%= check_box_tag 'accept'%>
  <%= submit_tag 'Save' %>
<% end %>
ob264
  • 535
  • 2
  • 6