Created
April 4, 2015 03:37
-
-
Save bntzio/f66d756826c25701548b to your computer and use it in GitHub Desktop.
incoming test 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class IncomingController < ApplicationController | |
skip_before_action :verify_authenticity_token, only: [:create] | |
def create | |
# Take a look at these in your server logs | |
# to get a sense of what you're dealing with. | |
puts "INCOMING PARAMS HERE: #{params}" | |
# You put the message-splitting and business | |
# magic here. | |
# Find the user by using params[:sender] | |
@user = User.find_by(email: params[:sender]) | |
# Find the topic by using params[:subject] | |
@topic = Topic.find_by(user_id: @user.id, title: params[:subject]) | |
# Assign the url to a variable after retreiving it from params["body-plain"] | |
@url = params["body-plain"] | |
# Check if user is nil, if so, create and save a new user | |
@user = User.create(email: params[:sender], password: "#{params[:title]}_blocmarks") if @user.nil? | |
# Check if the topic is nil, if so, create and save a new topic | |
@topic = Topic.create(title: params[:subject], user_id: @user.id) if @topic.nil? | |
# Now that we're sure we have a valid user and topic, build and save a new bookmark | |
@bookmark = Bookmark.create(url: @url, topic_id: @topic.id) | |
# Assuming all went well. | |
head 200 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment