Mercury editor not saving default values

Need some help regarding mercury editor in rails.

I followed following tutorial to use mercury editor in my app

goo.gl/q960Ka

In above tutorial they wrote following lines in migration file before
doing rake db:migrate

Page.create(
title: ‘Lorem ipsum’,
content: 'Lorem ipsum…
)

which every-time update first entry with id=“1” of table instead of
creating new columns and then update it.

I use to set default value in migration table like

def change
create_table :pages do |t|
t.string :name
t.string :title => “test”
t.string :content => “test”
t.timestamps null: false
end
end
end

When I use to edit default values mercury didn’t save the values,
instead I got this error message

NoMethodError (undefined method []' for nil:NilClass): app/controllers/pages_controller.rb:9:insave_page’

This is my controller file pages_controller,rb for save_page

def save_page
page = Page.find(params[:id])
page.title = params[:content][:page_title][:value]
page.content = params[:content][:page_content][:value]
page.save!

render text: ''

end

Please tell me how can I edit my default values and save that edited
values in new entry instead of updating single entry everytime


Cheers!

Deepak Kumar Sharma
Blog: http://deekysharma.wordpress.com

" Mistakes are proof that you are trying "

On 5 March 2015 at 14:56, Deepak S. [email protected] wrote:

NoMethodError (undefined method []' for nil:NilClass): app/controllers/pages_controller.rb:9:insave_page’

This is my controller file pages_controller,rb for save_page

def save_page
page = Page.find(params[:id])
page.title = params[:content][:page_title][:value]
page.content = params[:content][:page_content][:value]

You have not told us which is line 9 but presumably it is one of the
above. Have a look in the log file to see what params is for the
request and check that it has the contents referenced above
(page_title and page_content and each of those has :value).

Colin

On Thu, Mar 5, 2015 at 10:34 PM, Colin L. [email protected] wrote:

You have not told us which is line 9 but presumably it is one of the
above. Have a look in the log file to see what params is for the
request and check that it has the contents referenced above
(page_title and page_content and each of those has :value).

Yes, it worked I looked into log file and I found I forgot to add “id”
element in some tags + passing wrong “id” elements in others. Somehow
I’m able to make to it run but I encountered with another error. Error
is like this

I followed Railscast mercury tutorial to set up future stuff like link
for edit, saving edited content etc.

http://railscasts.com/episodes/296-mercury-editor?view=asciicast

I’m able to edit but not able to save. I google alot but not able to
find solution. Can please tell me where I’m doing wrong

mercury.js

$(window).bind(‘mercury:ready’, function() {
var link = $(’#mercury_iframe’).contents().find(’#edit_link’);
Mercury.saveUrl = link.data(‘save-url’);
link.hide();
});

$(window).on(‘mercury:saved’, function() {
window.location.href = window.location.href.replace(//editor//i,
‘/’);
});

Error.

ActionController::RoutingError (No route matches [PUT]
“/quotations/3/mercury_update”):
/home/deepak/.rvm/gems/[email protected]/gems/actionpack-4.2.0/lib/action_dispatch/middleware/debug_exceptions.rb:21:in
call' web-console (2.1.0) lib/web_console/middleware.rb:37:incall’


Cheers!

Deepak Kumar Sharma
Blog: http://deekysharma.wordpress.com

" Mistakes are proof that you are trying "

On Fri, Mar 6, 2015 at 7:09 PM, Colin L. [email protected] wrote:

So is the problem that it should not be using that url, that it should
not be a PUT, or that the route is missing?

It should not using this url.


Cheers!

Deepak Kumar Sharma
Blog: http://deekysharma.wordpress.com

" Mistakes are proof that you are trying "

On 6 March 2015 at 13:33, Deepak S. [email protected] wrote:

$(window).bind(‘mercury:ready’, function() {
Error.

ActionController::RoutingError (No route matches [PUT]
“/quotations/3/mercury_update”):

So is the problem that it should not be using that url, that it should
not be a PUT, or that the route is missing?

Colin

On 6 March 2015 at 14:02, Deepak S. [email protected] wrote:

On Fri, Mar 6, 2015 at 7:09 PM, Colin L. [email protected] wrote:

So is the problem that it should not be using that url, that it should
not be a PUT, or that the route is missing?

It should not using this url.

What have you got in routes.rb to provide the route?

Colin

On Fri, Mar 6, 2015 at 8:49 PM, Colin L. [email protected] wrote:

What have you got in routes.rb to provide the route?

route.rb

resources :pages do
member { post :mercury_update }
end

pages_controller.rb

def mercury_update
page = Page.find(params[:id])
page.subject = params[:content][:page_subject][:value]
page.regard = params[:content][:page_regard][:value]
page.regardContent = params[:content][:page_regardContent][:value]
page.save!
render text: ‘’
end


Cheers!

Deepak Kumar Sharma
Blog: http://deekysharma.wordpress.com

" Mistakes are proof that you are trying "

On 6 March 2015 at 16:07, Deepak S. [email protected] wrote:

On Fri, Mar 6, 2015 at 8:49 PM, Colin L. [email protected] wrote:

What have you got in routes.rb to provide the route?

route.rb

That is routes.rb I hope

resources :pages do
member { post :mercury_update }
end

How does that provide the quotations route?

If you run rake routes you will see all the routes that defines.

Did you work right through a good tutorial such as railstutorial.org
as I suggested you did a little time ago?

Also look at the rails guide on routing (and all the other guides
actually).

Colin

On Fri, Mar 6, 2015 at 10:38 PM, Colin L. [email protected] wrote:

How does that provide the quotations route?

If you run rake routes you will see all the routes that defines.

Did you work right through a good tutorial such as railstutorial.org
as I suggested you did a little time ago?

Error Solved :slight_smile:

I used to solve error by changing method name in pages_controller.rb
file.

s / def mercury_update / def update

def update
page = Page.find(params[:id])
page.subject = params[:content][:page_subject][:value]
page.save!
render text: ‘’
end

Thanks for help.


Cheers!

Deepak Kumar Sharma
Blog: http://deekysharma.wordpress.com

" Mistakes are proof that you are trying "

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs