Monday 29 July 2013

Form auto fill using javascript and jquery. Passing and receiving parameters with windows.location

Scenario:

A Signup field with a signup button on index pages. if a user enter their email address and click on signup button it should be redirected to the devise signup path (new). And the email entered on the previous page should be filled in the signup registration form. first you need to override the devise registration form. which is partial.
I resolved the issue by using Javascript and jquery. below are the files I have made changes in.
_________________________________________________

index.html.erb
 
<%= render 'index_signup_label'%>

_________________________________________________

_index_signup_label.html.erb

<div class="signup-label" >
  <div style="margin-bottom: 5px"> <h2>Sign up for free</h2></br>
    <form action="/signup" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" novalidate>
    <input type="email" placeholder="Your best Email" value="" name="EMAIL" class="required email" id="mce-EMAIL">

    <%= button_tag "Free Signup", :id => 'signup-btn', :type => 'button',:class => "button primary" %>
   
</div></br>
    </form>
</div>

<script type="text/javascript">
$('#signup-btn').click(function(){
    var email = $("#mce-EMAIL").val();
    location.href = '<%= signup_path() %>?email='+email;
});

</script>
_____________________________________________

_user_form.html.erb

<p>
  <%= f.label :email, Spree.t(:email) %><br />
  <%= f.email_field :email, :class => 'title uemail', :onChange => 'changeallemail(this.value)', :onfocus => 'resetEl()' %>
</p>


<script type="text/javascript">
function get_param(name){
   if(name=(new RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)')).exec(location.search))
      return decodeURIComponent(name[1]);
}

$(document).ready(function() {
    var email = get_param('email');
    $('.uemail').val(email);
});
</script>





PHP my admin acccess denied password reset.

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
$ sudo service mysql start
$ mysql mysql -u root
$ UPDATE user SET password=PASSWORD('newpassword') WHERE user="root";

Restricting a page view to a specific action

Like you have a Nav bar on all pages and you want it to be different on Index Pages.

<div id="subheader" class="<%= 'slider-bg' if (controller_name.eql?('home') && action_name.eql?('index') )%>" >

Can't install RMagick 2.13.2. Can't find Magick-conf

Start working with an existing project

  1. Replace keys in shh Directory
  2. Set username and email
  3. Make a branch
  4. Clone
  5. Create a gemset
  6. Bundle install
  7. Run migration

RVM Commands

$ rvm current
$ rvm install x.y.z (version)
$ rvm use x.y.z
$ rvm use x.y.z@redmine_plugins

Thursday 4 July 2013

Customizing Refinery Page and Menu Titles

if you want to have a separate/different navigation menu title from your page title:
go to pages , edit pages, advanced options give your menu title there.... for SEO purposes browser title, meta keywords and meta description can also b given there.
Reference URL:
http://refinerycms.com/guides/page-titles-and-urls

Refinery adding additional page parts

for all pages if you want to add additional page parts go to config/initializers/refinery/pages.rb
uncomment  # config.default_parts = ["Body", "Side Body"] and add additional page part such as
 config.default_parts = ["Body", "Side Body", "Middle body"]


Changing Page Parts for a single Page

go on to the same part config/initializers/refinery/pages.rb
uncomment and change the following value to true
# config.new_page_parts = false
restart server
now go to your pages tab refinery and edit your home page You’ll notice a plus and minus button at the top right of the visual editor. Click on the plus icon and add a new page part titled “Middle Body” and click save. If you have modified your home.html.erb file, you can use the following snippet to output the new part’s content in your page:
<%= raw @page.content_for(:middle_body) %>

reference URL:
http://refinerycms.com/guides/changing-page-parts

Monday 1 July 2013

Cancan Ability

In your gemfile Include.
1. gem "cancan" 
2. install bundle. 
3. rails g cancan:ability
this will generate an ability class in your models. 
define your Abilities there like below.
but keep remember that you have already defined roles, 
such as you have a User model,
having two roles defined i.e admin and support.

class Ability
include CanCan::Ability
def initialize(user)
user||= User.new
can :read, :all
if user.role == 'admin'
can :manage, :all
else
can :read, :all
end
end
end

4. the resource on which you want to restrict a user,
 use the following filter in their controller.
                  load_and_authorize_resource
5. if you want restrict something in the views not to show.
<% if can? :manage, @flower %>
<td><%= link_to 'Edit', edit_flower_path(flower) %></td>
<% end %>
<% if can? :manage, @flower %>
<td><%= link_to 'Destroy', flower_path(flower),
method: :delete, data: { confirm: 'Are you sure?' } %></td>
<% end %>
 




 


Heroku Push and Assets precompile


  1. git push heroku master
  2. heroku run rake assets:precompile

Using Bootstrap with Rails 3.2

 Useful Resource :

http://railsapps.github.io/twitter-bootstrap-rails.html