end
end
- # GET /stories/new
- # GET /stories/new.js
- # GET /stories/new.json
def new
@story = Story.new
@story.supply_default
end
end
- # GET /stories/1/edit
- # GET /stories/1.js/edit
def edit
@story = Story.edit(params[:id], @author)
respond_to do |format|
end
end
- # POST /stories
- # POST /stories.json
def create
@story = Story.new
@story.supply_default
@story.attributes = params[:story]
@story.overwrite @author
- @comic = Comic.edit(@story.comic_id, @author)
- @panel = Panel.show(@story.panel_id, @author)
+ @comic = Comic.edit(@story.comic_id, @author) if @story.comic_id
+ @panel = Panel.show(@story.panel_id, @author) if @story.panel_id
respond_to do |format|
if @story.store
+ flash[:notice] = I18n.t('flash.notice.created', :model => Story.model_name.human)
format.html { redirect_to action: :comic, id: @story.comic_id }
format.json { render json: @story.story_as_json(@author) }
else
end
end
- # PUT /stories/1
- # PUT /stories/1.json
def update
@story = Story.edit(params[:id], @author)
ot = @story.t
@story.overwrite @author
respond_to do |format|
if @story.store ot
+ flash[:notice] = I18n.t('flash.notice.updated', :model => Story.model_name.human)
format.html { redirect_to action: :comic, id: @story.comic_id }
format.json { head :ok }
else
end
end
- # DELETE /stories/1
- # DELETE /stories/1.js
- # DELETE /stories/1.json
def destroy
@story = Story.edit(params[:id], @author)
- Story.transaction do
- @story.destroy_and_shorten
- end
respond_to do |format|
- format.html { redirect_to story_path(@story.comic) }
- format.json { head :ok }
+ if @story.destroy_and_shorten
+ flash[:notice] = I18n.t('flash.notice.destroyed', :model => Story.model_name.human)
+ format.html { redirect_to :controller => 'stories', :action => :comic, :id => @story.comic_id }
+ format.json { head :ok }
+ else
+ flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Story.model_name.human)
+ format.html { redirect_to story_path(@story) }
+ format.json { render json: @story.errors, status: :unprocessable_entity }
+ end
end
end
end