views:

43

answers:

2

This is deals_controller.rb. And it works like this, except two things.

  1. Not sure how to call Deal.count to add in my flash[:notice] . I get the hunch that its not calling something global.
  2. I need that contional statement back, as I'm pretty sure its responsible for actually adding the new @deal . So I assume my syntax is off. Do note, I added an extra 'end' when I uncomment this block.

    def create

    -# This will use the disclaimer_ids submitted from the check boxes in the view

    -# to add/delete deal.disclaimers entries to matched the list of checked boxes.

    @deal = Deal.new(params[:deal])

    -# <------I Need this commented out IF statement back ------->

    -#if @deal.valid? && @organization.deals << @deal

    flash[:notice] = 'Your promotion is published! You may find it in the number 1 position of our #{deal.count} previously posted promotions. To see your promotion, click here."'

    respond_to do |format|

    format.html { redirect_to organization_deals_path(@organization) }

    format.js

    -# I Need this IF Statement Back!

    -#else

    -#@disclaimers = Disclaimer.all

    -#render :action => 'new' end end

Thanks!

A: 

A couple of points:

  • You do not seem to be setting @organization before trying to use that in your if condition

  • If you want the total number of Deals this is called on the class i.e. Deal.count rather than deal.count

  • Even though you mention adding an extra end when uncommenting the if it looks like you are missing an end in the right place for your respond_to block

mikej
No, there are two ends at the end. And I would add a third for the respond_to. I don't think there's any need for more than three in this block.
Trip
Yes, but you need to end the `respond_to` block before the `else` - otherwise the `if` is outside the block but the `else` is inside it.
mikej
Ah ok gotcha. Great point. The #{Deal.count} doesn't work. What do you think that is?
Trip
A: 

First answer :

@deal_count = Deal.count

flash[:notice] = "blah blah blah #{@deal_count}"

I had single quotes around the flash notice. That's what was breaking this.

Second answer :

Yah for some reason this works now. I don't know what I did.

Trip