I know how so save a page title and favicon using the pismo gem with Rails 3.2.18. My question is how can I do the same with Rails 4 strong params it's kinda confusing to me.
Any help will be greatly appreciated, or if you know now of a better gem or a better way to save a page title and favicon will help 2. :)
# Rails 3.2.16
def create
require 'pismo'
bookmark = Bookmark.new(params[:bookmark])
bookmark.user_id = current_user.id
doc = Pismo::Document.new(bookmark.link)
@title = doc.title
@favicon = doc.favicon
bookmark.title = @title
bookmark.favicon = @favicon
flash[:error] = "your bookmark wasn't save" unless bookmark.save
redirect_to current_user
end
This is my rails 4 controller to save bookmark but I'm not really sure where or how to implement pismo gem.
# Rails 4.1.4
def create
@bookmark = current_user.bookmarks.build(bookmark_params)
if @bookmark.save
flash[:success] = "Bookmark save"
redirect_to statics_home_path
else
redirect_to statics_home_path
end
end
private
def bookmark_params
params.require(:bookmark).permit(:link, :title)
end
# this works with Pismo
# I'm sure it'll work with Nokogiri
def create
require 'pismo'
doc = Pismo::Document.new(bookmark_params[:link])
@bookmark = current_user.bookmarks.build(bookmark_params)
@bookmark.title = doc.title.to_s
if @bookmark.save
#flash[:success] = "Bookmark save"
redirect_to statics_home_path
else
redirect_to statics_home_path
#render 'statics/home'
end
end
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加