Skip to content

Instantly share code, notes, and snippets.

@px-amaac
Last active August 29, 2015 14:10
Show Gist options
  • Save px-amaac/d137d262a78acb156018 to your computer and use it in GitHub Desktop.
Save px-amaac/d137d262a78acb156018 to your computer and use it in GitHub Desktop.
_step.html.erb
<% if step.title != nil %>
<p>
<%= step.title %>
<%= step.problem %>
<%= step.solution %>
<%= link_to 'Show', tutorial_step_path(tutorial_id, step) %>
<%= link_to 'Destroy', tutorial_step_path(tutorial_id, step), method: :delete, data: { confirm: 'Are you sure?' } %>
</p>
<% end %>
<%= render partial: 'step', collection: @steps, :locals => { :tutorial_id => @tutorial.id } %>
class StepsController < ApplicationController
before_action :correct_user, only: [:create, :destroy, :show]
def show
@step = @tutorial.steps.find_by(id: params[:id])
#I have also tried @step = Step.find(params[:id])
end
private
def correct_user
@tutorial = current_user.tutorials.find_by(id: params[:tutorial_id])
redirect_to root_url if @tutorial.nil?
end
def step_params
params.require(:step).permit(:title, :problem, :solution)
end
end
<%= render 'tutorials/step', :locals => { :tutorial_id => @tutorial.id } %>
<!-- not sure how to define :step for the partial to use it. -->
<%= render 'tutorials/step', :locals => { :tutorial_id => @tutorial.id, :step => @step } %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment