ruby on rails - Wrong number of arguments (1 for 0) error when calling markdown method -


all,

i created markdown_title , markdown_body methods. when go show view page post model getting error: wrong number of arguments.

i believe markdown_title method(also markdown_body) might constructed incorrectly below in post.rb file. culprit?:

class post < activerecord::base   has_many :comments   has_one :summary   belongs_to :user    belongs_to :topic   #has_one :summary   default_scope {order('created_at desc')}    validates :title, length: {minimum: 5},  presence: true   validates :body,  length: {minimum: 20}, presence: true   validates :topic, presence: true   validates :user, presence: true    def markdown_title (render_as_markdown).render(self.title).html_safe end   def markdown_body (render_as_markdown).render(self.body).html_safe end  private  def render_as_markdown renderer = redcarpet::render::html.new extensions = {fenced_code_blocks: true} redcarpet = redcarpet::markdown.new(renderer, extensions) #return redcarpet end   end 

here code show.html.erb file error appearing while calling markdown_title method:

    <h1><%= @post.markdown_title @post.title %></h1>      <div class="row">     <div class="col-md-8">     <p><%= @post.body %></p>     </div>     <div class="col-md-4">     <% if policy(@post).edit? %>     <%= link_to "edit", edit_topic_post_path(@topic, @post), class: 'btn    btn-success' %>     <% end %>     </div>     </div>      <% if @post.summary.present? %>      <h1>post summary</h1>     <p><%= @post.summary.body %></p>      <% else %>    <%= form_for [@topic, @post, @post.build_summary] |f| %>     <%= f.text_field :body %>     <%= f.submit %>   <% end %>  <% end %> 

this post controller:

class postscontroller < applicationcontroller   #def index #for index page       #@posts = post.all        #authorize @posts     #end    def show       @post = post.find(params[:id])       @topic = topic.find(params[:topic_id])   end    def new       @topic = topic.find(params[:topic_id])       @post = post.new         authorize @post #authorize() check policy on new post resources        # if user present wll let render if no user present itll give exception   end    def create     #@post = post.new(params.require(:post).permit(:title, :body))     #require , permit make sure keys passed post.new     @topic = topic.find(params[:topic_id])     #@post = current_user.posts.build(params.require(:post).permit(:title, :body))     @post = current_user.posts.build(post_params)     @post.topic = @topic     authorize @post #authorize() check if user logged in if not itll give exception      if @post.save       flash[:notice] = "your new post created , saved."       redirect_to [@topic, @post] #takes new post created     else       flash[:error] = "there error saving post. please try again."       render :new # grabs new.html.erb file , pastes in view     end   end     def edit       @topic = topic.find(params[:topic_id])       @post = post.find(params[:id])       authorize @post   end    def update     @topic = topic.find(params[:topic_id])     @post = post.find(params[:id])     #@post_check = current_user.posts.build(post_params)     authorize @post      if @post.update_attributes(post_params)       flash[:notice] = "post updated , captured new update."       redirect_to [@topic, @post]     else       flash[:error] = "there error saving post. please try again."       render :new     end   end    private    def post_params     params.require(:post).permit(:title, :body)   end  end 

here error on view: enter image description here

you're calling markdown_title method parameter, in case, @post.title.

<h1><%= @post.markdown_title @post.title %></h1> 

in definition of post class, markdown_title method doesn't take parameters.

 def markdown_title    (render_as_markdown).render(self.title).html_safe  end 

that's why you're seeing wrong number of arguments (1 0) error.

since you're referencing self.title in markdown_title method, there's no reason pass @post.title it. remove @post.title you're calling markdown_title, , should go.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -