Forum: Ruby on Rails About haml and ruby on rail

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C47e75cdd405c006fb3a3a0cae147302?d=identicon&s=25 Nilesh Kulkarni (nilk_cse)
on 2009-04-14 13:55
Attachment: html_and_haml_file.txt (7 KB)

hi all,

   I am converting my view into HAML format i have done it with
"Html2Haml" command, then I removed all the "- end" from haml code and
my indentation is also correct,but now  it shows following errors
 I have kept code of show.html.erb and show.html.haml in attachment.

please help me I am not getting what exactly the error is?

compile error D:/aflatune/app/views/tracks/show.html.haml:33: syntax
error, unexpected tCONSTANT, expecting ')' _hamlout.open_tag("a", false,
false, false, false, {"class"=>"ActionLink"}, false, false, nil, nil,
:href => "#", :onclick => "if(confirm("Are you sure you want to delete
this track and associated media file?"))
showPane(parseLocation("#{track_path}"),true,false,true,"delete");return
false;" );
^ D:/aflatune/app/views/tracks/show.html.haml:53: syntax error,
unexpected kELSIF, expecting kEND  elsif @content_type == :youtube;
^ D:/aflatune/app/views/tracks/show.html.haml:91: syntax error,
unexpected kELSIF, expecting kEND  elsif;       ^
D:/aflatune/app/views/tracks/show.html.haml:107: syntax error,
unexpected kENSURE, expecting kEND
D:/aflatune/app/views/tracks/show.html.haml:109: syntax error,
unexpected $end, expecting kEND
Dd2d775dea75b381edb1bbf0600a0907?d=identicon&s=25 Marnen Laibow-Koser (marnen)
on 2009-04-14 19:15
Nilesh Kulkarni wrote:
[...]
>
> please help me I am not getting what exactly the error is?
>
> compile error D:/aflatune/app/views/tracks/show.html.haml:33:

That's the approximate location of the error.  What is in that file
around line 33?

> syntax
> error, unexpected tCONSTANT, expecting ')'
[...]

So you probably have a missing parenthesis or something like that.  But
we can't tell for sure without seeing the Haml file.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
C47e75cdd405c006fb3a3a0cae147302?d=identicon&s=25 Nilesh Kulkarni (nilk_cse)
on 2009-04-15 06:39
Marnen Laibow-Koser wrote:
> Nilesh Kulkarni wrote:
>
> So you probably have a missing parenthesis or something like that.  But
> we can't tell for sure without seeing the Haml file.
>
> Best,
> --
> Marnen Laibow-Koser
> http://www.marnen.org
> marnen@marnen.org

code of show.html.erb and show.html.haml is in "haml_and_html_file.txt"
attachment whth first post......
Dd2d775dea75b381edb1bbf0600a0907?d=identicon&s=25 Marnen Laibow-Koser (marnen)
on 2009-04-15 15:35
Nilesh Kulkarni wrote:
[...]
>
> code of show.html.erb and show.html.haml is in "haml_and_html_file.txt"
> attachment whth first post......

Sorry, I missed that.  I'll check it out.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
Dd2d775dea75b381edb1bbf0600a0907?d=identicon&s=25 Marnen Laibow-Koser (marnen)
on 2009-04-16 17:18
(Received via mailing list)
On Apr 14, 7:55 am, Nilesh Kulkarni <rails-mailing-l...@andreas-s.net>
wrote:
> error, unexpected tCONSTANT
[...]

OK, after some investigation, it looks like you have an unmatched
brace on line 32, which is exactly the sort of thing I suspected.

By the way, your view file contains some of the worst view code I've
ever seen -- it contains *way* too much logic, and much of that logic
is poorly written.  Some suggestions for fixing it up:

> - if @content_type == :mp3

You probably don't need this.  If I understand correctly what you're
doing, you should probably use respond_to in the controller to set up
different views.

> %script

Don't do that.  Learn about Haml filters and use :javascript instead.
Better yet, get rid of the inline JavaScript -- put it in a separate
file.

> - @ShareContentTitle = "#{@track.title} from album #{@album.title} at aflatune!"

This should be a method on the Track model.

> - trackIndex = 0;
> - for track in @album.tracks
> - suffix = "track_#{@track.to_param}_album_#{@album.id}_track_#{trackIndex}";
> %li.SongListItem
>   = track_link_html(suffix ,track.to_param, track.title)
> - trackIndex = trackIndex + 1

This is not properly indented, so it will not work (the entire body of
the for loop should be indented).  But even if it *were* properly
indented, it would be a bad way of doing things.  Ruby is not PHP --
don't write it as if it were.  In particular, in Ruby, it should
*never* be necessary to manually increment a loop index as you're
doing here trackIndex.  What you want is something like this:

- @album.tracks.each_with_index do |track, i|
  %li.SongListItem= track_link_html("track_#{@track.to_param}_album_#
{@album.id}_track_#{i}" ,track.to_param, track.title)

(yes, that's two lines instead of six!)

Also note that in Ruby, it is considered poor style to use CamelCase
variable names such as trackIndex.  The usual way of writing this
would be track_index.  You also don't need the semicolons at the end
of a line, and most people don't use them.  Please take the time to
study some good Ruby style.

> - @phrase = nil;
> - @video_id = @track[:bare_id]
> - @videoSearchHeadingTag = 'h3';
> - @videoSearchHeading = 'Related videos';
> - @showLongVideoResults = true
> = render :partial => 'home/video_search'

Setting this many variables in the view is a sure sign that something
is wrong.  These should either be model methods or set in the
controller.

Alternatively, if you're passing these values into the partial, please
read up on proper render :partial syntax, in particular the use
of :locals.  You probably want something like
render :partial => 'partial', :locals => {:video_id =>
@track.bare_id, :another_variable => 'another value', :next_variable
=> 'and so on'...}

> - elsif
> %h4
>   Sorry, the track could not be located in our system.

You have an elsif without a condition.  Did you mean else?  And why an
h4 when there's no h3 to nest it in?

Let me know if you have any further questions.  But if you're going to
work with Rails, *please* take the time to learn the Rails way of
doing things -- you will be much happier.

Best,
--
Marnen Laibow-Koser
marnen@marnen.org
http://www.marnen.org
C47e75cdd405c006fb3a3a0cae147302?d=identicon&s=25 Nilesh Kulkarni (nilk_cse)
on 2009-04-18 09:08
Marnen Laibow-Koser wrote:
> On Apr 14, 7:55�am, Nilesh Kulkarni <rails-mailing-l...@andreas-s.net>
> wrote:
>
> You have an elsif without a condition.  Did you mean else?  And why an
> h4 when there's no h3 to nest it in?
>
> Let me know if you have any further questions.  But if you're going to
> work with Rails, *please* take the time to learn the Rails way of
> doing things -- you will be much happier.
>


thank you for help i have corrected all, only one problem is

<a class="ActionLink" href="#" onclick='if(confirm("Are you sure you
want to delete this track and associated media file?"))
showPane(parseLocation("<%=track_path%>"),true,false,true,"delete");return
false;'>Delete</a>

is converted into =>

%a.ActionLink{ :href => "#", :onclick => "if(confirm("Are you sure you
want to delete this track and associated media file?"))
showPane(parseLocation("#{track_path}"),true,false,true,"delete");return
false;" } Delete

only this code is showing error rest all is correct............
Dd2d775dea75b381edb1bbf0600a0907?d=identicon&s=25 Marnen Laibow-Koser (marnen)
on 2009-04-18 15:12
Nilesh Kulkarni wrote:
[...]
>
> thank you for help i have corrected all,

I'm glad my advice was helpful.

> only one problem is
>
> <a class="ActionLink" href="#" onclick='if(confirm("Are you sure you
> want to delete this track and associated media file?"))
> showPane(parseLocation("<%=track_path%>"),true,false,true,"delete");return
> false;'>Delete</a>
>
> is converted into =>
>
> %a.ActionLink{ :href => "#", :onclick => "if(confirm("Are you sure you
> want to delete this track and associated media file?"))
> showPane(parseLocation("#{track_path}"),true,false,true,"delete");return
> false;" } Delete
>
> only this code is showing error rest all is correct............

The error (not a Ruby- or Haml-specific one) should be obvious with
about 5 seconds of inspection.  If you can't see it, you have no
business programming in *any* language.  Don't expect other people to do
your work for you on things this simple!

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
This topic is locked and can not be replied to.