SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A second set of eyes

    Could someone please look over the following code and inform me of what I've stupidly done to receive this error: argumets_controller .rb:49: syntax error, unexpected kEND, expecting $end

    Code Ruby:
    class ArgumentsController < ApplicationController
        before_filter :login_required
     
        def create
            @argument = Argument.create!(params[:argument])
     
            flash[:notice] = 'You have now argued your case'
     
            respond_to do |format|
                format.html
                format.js
            end
        end
     
        def show
            @argument = Argument.find(params[:id])
     
            respond_to do |format|
                format.html
                format.js
            end
        end
     
     
        def destroy
            @argument = Argument.find(params[:id])
     
            if is_creator?
                @argument.destroy
     
                flash[:notice]    =    'Your argument has been removed'
                respond_to do |format|
                    format.html { redirect_to :back }
                    format.js
                end
            else 
                flash[:notice] = 'That\'s not your own argument you\'re trying to delete fool'
                redirect_to :back
            end
        end
     
        protected
        #Check is user is allowed to edit and update options of this debate.
        def is_creator?
            if argument_creator? 
                true
            else
                false            
            end
        end    
     
    end
    Last edited by crankin; Jul 30, 2009 at 21:02. Reason: Wrong code

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,173
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    Without seeing any code I can only guess. But it sounds like something isn't nested properly. If the code is lengthy, indentation helps visualize various depth levels.

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey thanks pal, I managed to paste it so edited the above post. Ive been over it and over it and am still having no luck seeing the problem. From my experience with debugging, it's probably rediculously obvious
    Last edited by crankin; Jul 30, 2009 at 22:36.

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Hailsham, UK
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your code, copied and pasted, works fine for me (no syntax errors).

    Try changing your is_creator? method to

    Code Ruby:
    def is_creator?
      argument_creator?
    end

    as this has the same logic and is simpler (and removes one possible problem block).

    Try moving other actions out of the file until the culprit is found. (Divide and conquer.)

    Is there a difference between how you wrote it and how Sitepoint displayed it?

    This error often happens if you have one too many ends. This also means that the reported error line can be far removed from where you made the mistake.
    Last edited by calkie_f; Jul 31, 2009 at 02:02. Reason: Missed question mark

  5. #5
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,173
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    It looks like everything is matched up OK.
    In my copy, line 49 is the if's closing end:
    Code Ruby:
    43	    #Check is user is allowed to edit and update options of this debate.
    44	    def is_creator?
    45	        if argument_creator?
    46	            true
    47	        else
    48	            false           
    49	        end
    50	    end
    So with any luck, calkie_f's suggestion will fix things.

    I'm still fairly new to ruby syntax, do the true/false need "return"?

  6. #6
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Hailsham, UK
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague View Post
    I'm still fairly new to ruby syntax, do the true/false need "return"?
    Nope. The last expression evaluated automatically becomes the return value of the method.

    As I've been caught out with unexpected return values I now use return with more complicated code since there's a chance to accidentally change a return value later.

  7. #7
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your advice guys, I tried adjusting the protected function but it made no difference, so I commented out the entire contents and went through each function 1 by 1. Even with everything commented out except the class declaration and it's end tag- it still threw out the same error.

    It's a strange one

  8. #8
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,173
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    I just noticed a discrepency in the controller name i.e. "n"
    Code:
    argumets_controller .rb:49: syntax error, unexpected kEND, expecting $end
    Code Ruby:
    class ArgumentsController < ApplicationController
    Although I'm a bit surprised the error message doesn't say "not exists" or whatever instead of unexpected end. But I guess like most error messages, once you know what they mean, you know what they mean.

  9. #9
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I believe that was just my typing error in my first post. I still have no idea what is causing this error but it's still persisting.

    Like I said even with
    class ArgumentsController < ApplicationController
    end

    application controller works fine too because other controllers are working as expected.

  10. #10
    SitePoint Enthusiast
    Join Date
    May 2008
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Copy and paste the error you get when the controller is empty.

    Thanks.

  11. #11
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I empty the class and just leave class
    Code Ruby:
    ArgumentsController < ApplicationController 
    end

    Code:
    SyntaxError in ArgumentsController#create  C:/Documents and Settings/Jaap/BitNami RubyStack projects/debate/app/controllers/arguments_controller.rb:2: syntax error, unexpected kEND, expecting $end
    Keeping in mind there is no create method, If I add one so the controller looks like this

    Code Ruby:
    class ArgumentsController < ApplicationController 
         def create         
    @argument = Argument.create!(params[:id])                  
    flash[:notice] = "Argument created"         
    redirect_to :back     
    end  
    end

    Then I receive pretty much the same error

    Code:
    SyntaxError in ArgumentsController#create  C:/Documents and Settings/Jaap/BitNami RubyStack projects/debate/app/controllers/arguments_controller.rb:10: syntax error, unexpected kEND, expecting $end
    Last edited by crankin; Aug 3, 2009 at 18:21. Reason: formatting error

  12. #12
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,173
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    Not that I'm an expert, but everything looks fine to me. This is a real puzzle all right. Might it be some stray "white-space" somewhere like a tab or newline? i.e. "invisible".
    Did you save the file using a plain-text editor, without a BOM?

  13. #13
    SitePoint Enthusiast
    Join Date
    May 2008
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That fact it's still trying to pull in a create method even when it's empty is very suspect.

    What's the stack trace say that comes with the error? Might lead us to the source of the problem.

  14. #14
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Hailsham, UK
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The whinge about #create method looks like a red herring from something Rails is doing (it happens for me too). The keyword 'class' is missing from the empty controller. That is,

    Code Ruby:
    ArgumentsController < ApplicationController
    end

    should be

    Code Ruby:
    class ArgumentsController < ApplicationController
    end

  15. #15
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you think it could have something to do with my associations or routes?

  16. #16
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Hailsham, UK
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi crankin,

    Had a look at the files you sent me.

    Copy and paste content from arguments_controller.rb to another file.

    Delete the file arguments_controller.rb and create it again as a new file and paste your content back in.

    Worked for me -- maybe a file encoding issue like Mittineague was suggesting in the original file. Using Textmate nothing I did to that original file would stop Ruby complaining.

    Good luck!

  17. #17
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, haha thanks man, it worked instantly. About a weeks worth of trouble.

    Solved.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •