Skip to content

Instantly share code, notes, and snippets.

@dohoonk
Last active March 16, 2016 21:28
Show Gist options
  • Save dohoonk/8faeb0ccfb9ed6f5e9a3 to your computer and use it in GitHub Desktop.
Save dohoonk/8faeb0ccfb9ed6f5e9a3 to your computer and use it in GitHub Desktop.
Aasm

bin/rails g controller my_campaigns

resources :my_campaigns, only: [:index]

<%=link_to "My projects", my_campaigns_path%>

before_action :authernticate_user

def index @campaigns = current_user.campaigns end

<%= @campaign.aasm_state %>
----------------------------------------------------------------------- Stick to Convention

bin/rails g controller publishings

insdie the campaigns routes resources :publishing, only: [:create]

<% if @campaign.draft? %> <%= link_to "Publish", campaign_publishings_path(@campaign), method: :post,class: "btn btn-primary", data: {confirm: "Are you sure? you wont be able to edit the campaign after it's published."}%> <% end %>

in the publishings controller before_action :authenticate_user!

def create campaign = current_user.campaigns.friendly.find params[:campaign_id] if campaign.publish! redirect_to campaign, notice: "Published!" else redirect_to campaign, alert: "Can't publish!" end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment