Ruby on Rails: Action without View

后端 未结 4 1631
伪装坚强ぢ
伪装坚强ぢ 2021-02-14 13:48

I have what I think is a very simple problem. I\'m coming from a PhP background, and used to do this all the time, so I may be looking at this the wrong way.

I am trying

相关标签:
4条回答
  • 2021-02-14 14:10

    Have a look at http://guides.rubyonrails.org/layouts_and_rendering.html#using-render

    You might need render :nothing => true

    EDIT: misread your question, render :text => "yourtext" should fit your needs

    0 讨论(0)
  • 2021-02-14 14:11

    In Rails 5 you need to use 'plain':

    render plain: params[:email]
    
    0 讨论(0)
  • 2021-02-14 14:16

    You'd need something like this:

    def mcsubscribe
      # Do something to unsubscribe
      respond_to do |format|
        format.html { redirect_to(success_page) }
        format.js   { render :text => params[:email] }
      end  
    end
    

    If ajax is used, the params[:email] is send as text. If a HTML format is required (ie user clicked a link or filled in a regular form) a redirect is issued to tell the user the subscription has been successful.

    0 讨论(0)
  • 2021-02-14 14:29

    Using

    print params[:email]
    

    will just print that value to the application logs, not into the response.

    You want this:

    render :text => params[:email]
    
    0 讨论(0)
提交回复
热议问题