Skip to content

Instantly share code, notes, and snippets.

@richardsondx
Created February 26, 2012 06:48
Show Gist options
  • Save richardsondx/1914520 to your computer and use it in GitHub Desktop.
Save richardsondx/1914520 to your computer and use it in GitHub Desktop.
Assign a value to a param, from 2 choices.
def new
@micropost = Micropost.new(:tag => '4' )
# Change the value of 'Micropost.find(..).to_guys' to True or False depending on what button was pressed
if request.post?
if params[:name].include?( 'to_guys' )
@micropost.to_guys = true
flash[:notice] = 'This post was sent to guys'
else
@micropost.to_guys = false
flash[:notice] = 'This post was sent to girls'
end
end
end
class CreateMicroposts < ActiveRecord::Migration
def change
create_table :microposts do |t|
t.boolean :to_guys
t.string :tag
t.boolean :approved
t.string :content
t.timestamps
end
end
end
<%= form_for @micropost do |f| %>
<p>
<fieldset>
<legend> Enter something </legend>
<%= f.text_field :content, :size => 90 %> <br/>
<%= f.label "Send to who?:" %>
<%= submit_tag "to Guys", :name => "to_guys" %>
<%= submit_tag "to Girls", :name => "to girls" %>
</p>
</fieldset>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment