Skip to content

Integrate with ruby

Miguel Michelson Martinez edited this page Sep 23, 2016 · 2 revisions

Ruby:

Dante sends params from the view to the controller within a "body" key, with he HTML (in string form) as the value. With Rails' strong params, you will need to rename it to whatever that ethod will accept. To post successfully to the controller, you will probably need to modify the params ithin the "create" action. For example, if you had a resource called "Story", with each Story having 1 ext field called "content", you would rename and merge the params like so:

  def create
    story = {:story => {:content => params[:body]}}
    params.merge!(story)
    @story = Story.new(story_params)

    respond_to do |format|
      if @story.save
        format.html { redirect_to @story, notice: 'Story was successfully reated.' }
        format.json { render :show, status: :created, location: @story }
      else
        format.html { render :new }
        format.json { render json: @story.errors, status: unprocessable_entity }
      end
    end
  end

HTML on the show.html.erb page:

To display the content from the editor within a view,

  <%= @story.content.html_safe %>

thanks to @piratebroadcast for this entry!

Clone this wiki locally