load partial with jquery and rails

后端 未结 5 1368
深忆病人
深忆病人 2021-01-04 23:54

Im curious about what the best way to load a rails partial with jquery. So far I have tried a solution not working:

$(\'#imagecontent\').load(\'/newsletters/         


        
5条回答
  •  太阳男子
    2021-01-05 00:22

    You should not be able to access Template files (.erb) from HTTP requests, this is very bad practice. I suggest you put them outside your web servers path and access them only through your application.

    I'm not sure about Rails, but I suppose you need to create a separate controller (or whatever) to do this.

    EDIT this is because .erb files are Embedded Ruby files, and if you try to request them you will get all unwanted data, like <%= page_title %>, that you don't want to show the users. Therefore you need to pass these .erb files through your Rails application so that they are properly interpreted into HTML.

提交回复
热议问题