ruby - Rails 4: create custom object in controller -


i'm trying create provider oembed in rails 4 route, controller , action created.

but i'm not able create object parameters needed oembed (e.g. type, version, html, ...)

i trying way:

class servicescontroller < applicationcontroller      def oembed         # project id         url = params[:url].split("/")         project_id = url[4]          @project = project.find(project_id)         html = render_to_string :partial => "projects/oembed", :formats => [:html], :locals => { :project => @          # here's problem:         oembed_response["type"] = "rich"         oembed_response["version"] = "1.0"         oembed_response["title"] = @project.name         oembed_response["html"] = html          respond_to | format |             if(@project)                 format.html { render :text => "test" }                 format.json { render json: oembed_response, status: :ok }                 format.xml { render xml: oembed_response, status: :ok }             else                 # error             end         end     end end 

i following error:

nameerror (undefined local variable or method oembed_response' #<servicescontroller:0x007f9a8be579a0>): app/controllers/services_controller.rb:11:inoembed'

how can achieve create custom object needed attributes without model , (strong-) parameters it's done?

am missing something?

thanks in advance!

regards,

chri

initialize oembed_response empty hash first:

oembed_response = {} 

unrelated error, should change way object url id. routes should parse id automatically you, eg. when have in routes.rb file:

get "/projects/oembed/:id" => 'services#oembed' 

then can access id (given :id in routes path) directyl params hash:

project_id = params[:id] 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -