Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined method `text' for #<Phlex::Markdown:0x0000000111d47058....> #6

Closed
Sandbagger opened this issue Jan 28, 2024 · 2 comments
Closed

Comments

@Sandbagger
Copy link

Sandbagger commented Jan 28, 2024

I am trying to take phlex-markdown for a spin in a Rails app but I am encountering this error:

NoMethodError (undefined method `text' for #<Phlex::Markdown:0x0000000111d47058 @content="# \n## 2\n### 3\n#### 4\n##### 5\n###### 6\n", @_buffer="", @_context=#<Phlex::Context:0x0000000111d46fb8 @target="<h1></h1><h2>", @capturing=false>, @_view_context=nil, @_parent=nil>)

I've run the Rails-phlex generator to create a controller and view, and modified the view:

class Articles::IndexView < ApplicationView
  
  
  def template
   render Phlex::Markdown.new(content).call
  end

  def content 
    <<~MD
    # 
    ## 2
    ### 3
    #### 4
    ##### 5
    ###### 6
  MD
  end
end

Repo here: https://github.com/Sandbagger/rails-phlex-markdown

What am I missing?

@joeldrapper
Copy link
Collaborator

joeldrapper commented Jan 28, 2024

Hey @Sandbagger, the released version of this is is broken. For now, can you install directly from GitHub? This is still in beta and there are other changes coming in the next few weeks so I don’t want to go through cutting a release yet.

gem "phlex-markdown", git: "https://github.com/phlex-ruby/phlex-markdown.git"

@Sandbagger
Copy link
Author

Sandbagger commented Jan 28, 2024

@joeldrapper Thank yooou for the fast response!

In case it is of use to others here is how I managed to connect the dots...

gem "phlex-markdown", git: "https://github.com/phlex-ruby/phlex-markdown.git"

In place of render use plain and don't forget to html_safe the output...

class Articles::IndexView < ApplicationView
  def template
    plain Phlex::Markdown.new(content).call.html_safe
  end

  def content 
    <<~MD
    # 
    ## 2
    ### 3
    #### 4
    ##### 5
    ###### 6
  MD
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants