Ruby haml意外结束错误

时间:2015-05-04 22:08:45

标签: ruby-on-rails ruby haml simple-form

= simple_form_for @pin, html: { multipart: true} do |f|
- if @pin.errors.any?
    #errors
        %h2
        = pluralize(@pin.errors.count, "errors")
        prevented this Pin from saving
        %ul
            - @pin.errors.full_messages.each do |msg|
            %li= msg
.form-group
    = f.input :title, input_html: { class: 'form-control' } 

.form-group
    = f.input :description, input_html:{ class: 'form-control' }     

= f.button :submit, class: "btn btn-primary"    

有人可以告诉我为什么这会让我回想起下面针对rails的错误

  

/Users/frankchen/project/pin_board/app/views/pins/_form.html.haml:17:语法错误,意外的keyword_ensure,期待keyword_end ......:Util.html_safe(_erbout);确保; @haml_buffer = @haml_buffer .... ... ^ /Users/frankchen/project/pin_board/app/views/pins/_form.html.haml:20:语法错误,意外的输入结束,期待keyword_end

3 个答案:

答案 0 :(得分:4)

如果它是HAML,它很可能是缩进问题。我无法匹配您提供的行号,因为我们只看到了代码片段,但我猜测这两行之间的缩进是关闭的:

- @pin.errors.full_messages.each do |msg|
%li= msg

答案 1 :(得分:1)

当您粘贴在代码中时,无法确定代码缩进是否搞砸了,或者您实际拥有它的方式,但是,您有几个错误缩进。例如:

= simple_form_for @pin, html: { multipart: true} do |f|
- if @pin.errors

- if应缩进2个空格。所以它在上面的简单形式的范围内。您ul

中的li及其each也是如此

答案 2 :(得分:0)

就我而言,当我删除- @pin.errors.full_messages.each do |msg|- @pin.errors.full_messages.each do |msg|之间的缩进时,它有效。我仍然不知道原因,因为@ul应该在%ul - @pin.errors.full_messages.each do |msg| %li= msg 标签内。

try {

                    String path = newString;
                    File myFile = new File(path);
                    Intent sharingIntent = new Intent("android.intent.action.SEND");
                    sharingIntent.setType(getMimeType(myFile.getPath()));
                    sharingIntent.putExtra("android.intent.extra.STREAM",Uri.fromFile(myFile));
                    startActivity(Intent.createChooser(sharingIntent,"Share using"));
                } catch (Exception e) {
                    Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
             }



public String getMimeType(String filePath) {
        String type = null;
        String extension = getFileExtensionFromUrl(filePath);
        if (extension != null) {
            MimeTypeMap mime = MimeTypeMap.getSingleton();
            type = mime.getMimeTypeFromExtension(extension);
        }
        return type;
    }

    public String getFileExtensionFromUrl(String url) {
        int dotPos = url.lastIndexOf('.');
        if (0 <= dotPos) {
            return (url.substring(dotPos + 1)).toLowerCase();
        }
        return "";
    }